aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2014-09-23 01:59:43 +0900
committerGodfrey Chan <godfreykfc@gmail.com>2014-09-23 01:59:43 +0900
commitca67632674e62426bf8b421d672692592e986091 (patch)
treee0670fd94daed28a04291e429c5e66549cc3aee9 /activemodel/lib/active_model
parentb52add7e17d19808a668ebf40eb31371d167d015 (diff)
downloadrails-ca67632674e62426bf8b421d672692592e986091.tar.gz
rails-ca67632674e62426bf8b421d672692592e986091.tar.bz2
rails-ca67632674e62426bf8b421d672692592e986091.zip
Move the array to a constant
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r--activemodel/lib/active_model/validations.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb
index 08c2b02f19..60439f5631 100644
--- a/activemodel/lib/active_model/validations.rb
+++ b/activemodel/lib/active_model/validations.rb
@@ -86,6 +86,8 @@ module ActiveModel
validates_with BlockValidator, _merge_attributes(attr_names), &block
end
+ VALID_OPTIONS_FOR_VALIDATE = [:on, :if, :unless].freeze
+
# Adds a validation method or block to the class. This is useful when
# overriding the +validate+ instance method becomes too unwieldy and
# you're looking for more descriptive declaration of your validations.
@@ -142,12 +144,11 @@ module ActiveModel
# value.
def validate(*args, &block)
options = args.extract_options!
- valid_keys = [:on, :if, :unless]
if args.all? { |arg| arg.is_a?(Symbol) }
options.each_key do |k|
- unless valid_keys.include?(k)
- raise ArgumentError.new("Unknown key: #{k.inspect}. Valid keys are: #{valid_keys.map(&:inspect).join(', ')}. Perhaps you meant to call validates instead of validate.")
+ unless VALID_OPTIONS_FOR_VALIDATE.include?(k)
+ raise ArgumentError.new("Unknown key: #{k.inspect}. Valid keys are: #{VALID_OPTIONS_FOR_VALIDATE.map(&:inspect).join(', ')}. Perhaps you meant to call `validates` instead of `validate`?")
end
end
end