Class Index [+]

Quicksearch

ActiveModel::Validations::FormatValidator

Public Instance Methods

check_validity!() click to toggle source
    # File lib/active_model/validations/format.rb, line 15
15:       def check_validity!
16:         unless options.include?(:with) ^ options.include?(:without)  # ^ == xor, or "exclusive or"
17:           raise ArgumentError, "Either :with or :without must be supplied (but not both)"
18:         end
19: 
20:         check_options_validity(options, :with)
21:         check_options_validity(options, :without)
22:       end
validate_each(record, attribute, value) click to toggle source
    # File lib/active_model/validations/format.rb, line 5
 5:       def validate_each(record, attribute, value)
 6:         if options[:with]
 7:           regexp = option_call(record, :with)
 8:           record_error(record, attribute, :with, value) if value.to_s !~ regexp
 9:         elsif options[:without]
10:           regexp = option_call(record, :without)
11:           record_error(record, attribute, :without, value) if value.to_s =~ regexp
12:         end
13:       end

Private Instance Methods

check_options_validity(options, name) click to toggle source
    # File lib/active_model/validations/format.rb, line 35
35:       def check_options_validity(options, name)
36:         option = options[name]
37:         if option && !option.is_a?(Regexp) && !option.respond_to?(:call)
38:           raise ArgumentError, "A regular expression or a proc or lambda must be supplied as :#{name}"
39:         end
40:       end
option_call(record, name) click to toggle source
    # File lib/active_model/validations/format.rb, line 26
26:       def option_call(record, name)
27:         option = options[name]
28:         option.respond_to?(:call) ? option.call(record) : option
29:       end
record_error(record, attribute, name, value) click to toggle source
    # File lib/active_model/validations/format.rb, line 31
31:       def record_error(record, attribute, name, value)
32:         record.errors.add(attribute, :invalid, options.except(name).merge!(:value => value))
33:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.