-
-
Save burningTyger/566276 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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