Skip to content

Instantly share code, notes, and snippets.

@knowtheory
Created September 5, 2010 19:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save knowtheory/566268 to your computer and use it in GitHub Desktop.
Save knowtheory/566268 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