aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-06-21 12:17:24 +0200
committerJosé Valim <jose.valim@gmail.com>2010-06-21 12:17:24 +0200
commit0421fb7a913c1c8a7e07a395106bbc65e75e9d45 (patch)
tree1f8c19f62541dc51be6c072d2d0cc8f904188af9 /activemodel/lib/active_model/validations
parent26392c4ac57e27c63984d47c6326c13f502d5786 (diff)
downloadrails-0421fb7a913c1c8a7e07a395106bbc65e75e9d45.tar.gz
rails-0421fb7a913c1c8a7e07a395106bbc65e75e9d45.tar.bz2
rails-0421fb7a913c1c8a7e07a395106bbc65e75e9d45.zip
Refactor previous commit a bit [#4057 state:resolved]
Diffstat (limited to 'activemodel/lib/active_model/validations')
-rw-r--r--activemodel/lib/active_model/validations/exclusion.rb2
-rw-r--r--activemodel/lib/active_model/validations/format.rb4
-rw-r--r--activemodel/lib/active_model/validations/inclusion.rb2
-rw-r--r--activemodel/lib/active_model/validations/length.rb4
-rw-r--r--activemodel/lib/active_model/validations/numericality.rb6
-rw-r--r--activemodel/lib/active_model/validations/with.rb3
6 files changed, 9 insertions, 12 deletions
diff --git a/activemodel/lib/active_model/validations/exclusion.rb b/activemodel/lib/active_model/validations/exclusion.rb
index 6fe43c7219..4138892786 100644
--- a/activemodel/lib/active_model/validations/exclusion.rb
+++ b/activemodel/lib/active_model/validations/exclusion.rb
@@ -10,7 +10,7 @@ module ActiveModel
def validate_each(record, attribute, value)
if options[:in].include?(value)
- record.errors.add(attribute, :exclusion, options.except(:in).merge(:value => value))
+ record.errors.add(attribute, :exclusion, options.except(:in).merge!(:value => value))
end
end
end
diff --git a/activemodel/lib/active_model/validations/format.rb b/activemodel/lib/active_model/validations/format.rb
index 6f6933205f..104f403492 100644
--- a/activemodel/lib/active_model/validations/format.rb
+++ b/activemodel/lib/active_model/validations/format.rb
@@ -5,9 +5,9 @@ module ActiveModel
class FormatValidator < EachValidator
def validate_each(record, attribute, value)
if options[:with] && value.to_s !~ options[:with]
- record.errors.add(attribute, :invalid, options.except(:with).merge(:value => value))
+ record.errors.add(attribute, :invalid, options.except(:with).merge!(:value => value))
elsif options[:without] && value.to_s =~ options[:without]
- record.errors.add(attribute, :invalid, options.except(:with).merge(:value => value))
+ record.errors.add(attribute, :invalid, options.except(:without).merge!(:value => value))
end
end
diff --git a/activemodel/lib/active_model/validations/inclusion.rb b/activemodel/lib/active_model/validations/inclusion.rb
index 863f4da0ff..049b093618 100644
--- a/activemodel/lib/active_model/validations/inclusion.rb
+++ b/activemodel/lib/active_model/validations/inclusion.rb
@@ -10,7 +10,7 @@ module ActiveModel
def validate_each(record, attribute, value)
unless options[:in].include?(value)
- record.errors.add(attribute, :inclusion, options.except(:in).merge(:value => value))
+ record.errors.add(attribute, :inclusion, options.except(:in).merge!(:value => value))
end
end
end
diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb
index 77db437a33..c8a77ad666 100644
--- a/activemodel/lib/active_model/validations/length.rb
+++ b/activemodel/lib/active_model/validations/length.rb
@@ -7,6 +7,7 @@ module ActiveModel
CHECKS = { :is => :==, :minimum => :>=, :maximum => :<= }.freeze
DEFAULT_TOKENIZER = lambda { |value| value.split(//) }
+ RESERVED_OPTIONS = [:minimum, :maximum, :within, :is, :tokenizer, :too_short, :too_long]
def initialize(options)
if range = (options.delete(:in) || options.delete(:within))
@@ -50,9 +51,8 @@ module ActiveModel
next if valid_value
- reserved_options = [:minimum, :maximum, :within, :is, :tokenizer, :too_short, :too_long]
record.errors.add(attribute, MESSAGES[key],
- options.except(*reserved_options).merge(:count => check_value))
+ options.except(*RESERVED_OPTIONS).merge!(:count => check_value))
end
end
end
diff --git a/activemodel/lib/active_model/validations/numericality.rb b/activemodel/lib/active_model/validations/numericality.rb
index dcc3befb08..b6aff7aa6b 100644
--- a/activemodel/lib/active_model/validations/numericality.rb
+++ b/activemodel/lib/active_model/validations/numericality.rb
@@ -7,6 +7,8 @@ module ActiveModel
:equal_to => :==, :less_than => :<, :less_than_or_equal_to => :<=,
:odd => :odd?, :even => :even? }.freeze
+ RESERVED_OPTIONS = CHECKS.keys + [:only_integer]
+
def initialize(options)
super(options.reverse_merge(:only_integer => false, :allow_nil => false))
end
@@ -76,10 +78,8 @@ module ActiveModel
end
def filtered_options(value)
- reserved_options = [:allow_nil, :odd, :even, :not_an_integer, :only_integer, :allow_nil, :less_than]
- options.except(*reserved_options).merge(:value => value)
+ options.except(*RESERVED_OPTIONS).merge!(:value => value)
end
-
end
module HelperMethods
diff --git a/activemodel/lib/active_model/validations/with.rb b/activemodel/lib/active_model/validations/with.rb
index a2e870d714..200efd4eb5 100644
--- a/activemodel/lib/active_model/validations/with.rb
+++ b/activemodel/lib/active_model/validations/with.rb
@@ -1,6 +1,4 @@
module ActiveModel
-
- # == Active Model validates_with method
module Validations
module HelperMethods
private
@@ -11,7 +9,6 @@ module ActiveModel
end
module ClassMethods
-
# Passes the record off to the class or classes specified and allows them
# to add errors based on more complex conditions.
#