From ca67632674e62426bf8b421d672692592e986091 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 23 Sep 2014 01:59:43 +0900 Subject: Move the array to a constant --- activemodel/lib/active_model/validations.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'activemodel/lib/active_model') 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 -- cgit v1.2.3