Skip to content

Instantly share code, notes, and snippets.

@burningTyger
Forked from knowtheory/mixin_models.rb
Created September 5, 2010 20:00
Show Gist options
  • Save burningTyger/566276 to your computer and use it in GitHub Desktop.
Save burningTyger/566276 to your computer and use it in GitHub Desktop.
module Food
def self.included(model)
model.property :id, Serial
model.property :price, Integer, :min => 0 # builtin validation works just fine
model.property :calories, Integer, :min => 0
model.before(:valid?, :custom_validation)
end
def custom_validation
# does some stuff
if delicious?
return true
else
return [false, "error message! Not delicious enough!!!!!!!"]
end
end
end
class Taco
include DataMapper::Resource
include Food
end
class Ingredient
include DataMapper::Resource
include Food
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment