aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-06-10 22:00:55 +0200
committerXavier Noria <fxn@hashref.com>2010-06-10 22:00:55 +0200
commit63560660062d552d6bbebec007154f0c639bf865 (patch)
tree0ff7ee5c1a63815685e9640ca4a9ceafb7732178 /activemodel
parent59e89facc2264322bcab59c9a8622380b62d4d40 (diff)
parent61fc7a455099f179de88967f403f2038b9d3c821 (diff)
downloadrails-63560660062d552d6bbebec007154f0c639bf865.tar.gz
rails-63560660062d552d6bbebec007154f0c639bf865.tar.bz2
rails-63560660062d552d6bbebec007154f0c639bf865.zip
Merge remote branch 'rails/master'
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/validations.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb
index f472f50f9b..d7e3544849 100644
--- a/activemodel/lib/active_model/validations.rb
+++ b/activemodel/lib/active_model/validations.rb
@@ -50,9 +50,8 @@ module ActiveModel
extend HelperMethods
include HelperMethods
- define_callbacks :validate, :scope => :name
-
attr_accessor :validation_context
+ define_callbacks :validate, :scope => :name
class_attribute :_validators
self._validators = Hash.new { |h,k| h[k] = [] }
@@ -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.