Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creating custom validations in MongoMapper
module MyCustomValidation
extend ActiveSupport::Concern
module InstanceMethods
def do_the_validation
errors.add(:foo, 'is not valid') unless some_condition_is_met?
end
def some_condition_is_met?
true
end
end
module ClassMethods
def validate_my_stuff
validate :do_the_validation
end
end
end
class MyThing
include MongoMapper::Document
plugin MyCustomValidation
validate_my_stuff
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment