diff options
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/validations.rb | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index 7520e0331d..d7e3544849 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -50,11 +50,10 @@ module ActiveModel extend HelperMethods include HelperMethods - define_callbacks :validate, :scope => :name - attr_accessor :validation_context + define_callbacks :validate, :scope => :name - class_inheritable_accessor :_validators + class_attribute :_validators self._validators = Hash.new { |h,k| h[k] = [] } end @@ -128,8 +127,7 @@ module ActiveModel set_callback(:validate, *args, &block) end - # List all validators that being used to validate the model using +validates_with+ - # method. + # List all validators that being used to validate the model using +validates_with+ method. def validators _validators.values.flatten.uniq end @@ -139,9 +137,17 @@ module ActiveModel _validators[attribute.to_sym] end + # Check if method is an attribute method or not. def attribute_method?(attribute) method_defined?(attribute) end + + # Copy validators on inheritance. + def inherited(base) + dup = _validators.dup + base._validators = dup.each { |k, v| dup[k] = v.dup } + super + end end # Returns the Errors object that holds all information about attribute error messages. |