Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.