aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations/format.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel/lib/active_model/validations/format.rb')
-rw-r--r--activemodel/lib/active_model/validations/format.rb30
1 files changed, 15 insertions, 15 deletions
diff --git a/activemodel/lib/active_model/validations/format.rb b/activemodel/lib/active_model/validations/format.rb
index d5427c2b03..9a9e7eca4d 100644
--- a/activemodel/lib/active_model/validations/format.rb
+++ b/activemodel/lib/active_model/validations/format.rb
@@ -8,6 +8,20 @@ module ActiveModel
record.errors.add(attribute, :invalid, :default => options[:message], :value => value)
end
end
+
+ def check_validity!
+ unless options.include?(:with) ^ options.include?(:without) # ^ == xor, or "exclusive or"
+ raise ArgumentError, "Either :with or :without must be supplied (but not both)"
+ end
+
+ if options[:with] && !options[:with].is_a?(Regexp)
+ raise ArgumentError, "A regular expression must be supplied as the :with option of the configuration hash"
+ end
+
+ if options[:without] && !options[:without].is_a?(Regexp)
+ raise ArgumentError, "A regular expression must be supplied as the :without option of the configuration hash"
+ end
+ end
end
module ClassMethods
@@ -43,21 +57,7 @@ module ActiveModel
# not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
def validates_format_of(*attr_names)
- options = attr_names.extract_options!
-
- unless options.include?(:with) ^ options.include?(:without) # ^ == xor, or "exclusive or"
- raise ArgumentError, "Either :with or :without must be supplied (but not both)"
- end
-
- if options[:with] && !options[:with].is_a?(Regexp)
- raise ArgumentError, "A regular expression must be supplied as the :with option of the configuration hash"
- end
-
- if options[:without] && !options[:without].is_a?(Regexp)
- raise ArgumentError, "A regular expression must be supplied as the :without option of the configuration hash"
- end
-
- validates_with FormatValidator, options.merge(:attributes => attr_names)
+ validates_with FormatValidator, _merge_attributes(attr_names)
end
end
end