Class: ActiveModel::Validations::RespondToValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/active_validators/active_model/validations/respond_to_validator.rb

Constant Summary collapse

RESERVED_OPTIONS =
[:if, :unless]

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/active_validators/active_model/validations/respond_to_validator.rb', line 5

def validate_each(record,attribute,value)
  responders = options.dup
  RESERVED_OPTIONS.each do |opt,should_apply| responders.delete(opt) end
  responders.each do |method,dummy|
    record.errors.add(attribute) unless value.respond_to? method
  end
end