Created
May 21, 2014 06:51
-
-
Save robjacoby/82a9d3bfc4b802c7a919 to your computer and use it in GitHub Desktop.
validatable module
This file contains hidden or 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 Validatable | |
extend ActiveSupport::Concern | |
# Required dependency for ActiveModel::Errors | |
extend ActiveModel::Naming | |
def validate! | |
raise NotImplementedError, 'You need to implement this in the parent class' | |
end | |
def errors | |
@errors ||= ActiveModel::Errors.new(self) | |
end | |
# The following methods are needed to be minimally implemented | |
def read_attribute_for_validation(attr) | |
send(attr) | |
end | |
ClassMethods do | |
def human_attribute_name(attr, options = {}) | |
attr | |
end | |
def lookup_ancestors | |
[self] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment