aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations
diff options
context:
space:
mode:
authorRobin Mehner <robin@coding-robin.de>2014-06-22 12:22:27 +0200
committerRobin Mehner <robin@coding-robin.de>2014-06-22 12:22:27 +0200
commit64a05a928c50a770c6562ac1840772c5d6ad6f53 (patch)
tree9b880082247bc0e31a73690a1614f2e04333501c /activemodel/lib/active_model/validations
parentc2d5b31073d9e0dbe779a74c0741e3fea79840fa (diff)
downloadrails-64a05a928c50a770c6562ac1840772c5d6ad6f53.tar.gz
rails-64a05a928c50a770c6562ac1840772c5d6ad6f53.tar.bz2
rails-64a05a928c50a770c6562ac1840772c5d6ad6f53.zip
`only_integer` of `NumericalityValidator` now allows procs and symbols
Diffstat (limited to 'activemodel/lib/active_model/validations')
-rw-r--r--activemodel/lib/active_model/validations/numericality.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/validations/numericality.rb b/activemodel/lib/active_model/validations/numericality.rb
index a9fb9804d4..5bd162433d 100644
--- a/activemodel/lib/active_model/validations/numericality.rb
+++ b/activemodel/lib/active_model/validations/numericality.rb
@@ -30,7 +30,7 @@ module ActiveModel
return
end
- if options[:only_integer]
+ if allow_only_integer?(record)
unless value = parse_raw_value_as_an_integer(raw_value)
record.errors.add(attr_name, :not_an_integer, filtered_options(raw_value))
return
@@ -75,6 +75,17 @@ module ActiveModel
filtered[:value] = value
filtered
end
+
+ def allow_only_integer?(record)
+ case options[:only_integer]
+ when Symbol
+ record.send(options[:only_integer])
+ when Proc
+ options[:only_integer].call(record)
+ else
+ options[:only_integer]
+ end
+ end
end
module HelperMethods
@@ -121,6 +132,7 @@ module ActiveModel
# * <tt>:equal_to</tt>
# * <tt>:less_than</tt>
# * <tt>:less_than_or_equal_to</tt>
+ # * <tt>:only_integer</tt>
#
# For example:
#