Class: ActiveModel::Validations::AcceptanceValidator
Instance Attribute Summary
#attributes
#options
Instance Method Summary
collapse
#check_validity!, #validate
kind, #kind, #validate
Constructor Details
Returns a new instance of AcceptanceValidator.
6
7
8
|
# File 'lib/active_model/validations/acceptance.rb', line 6
def initialize(options)
super(options.reverse_merge(:allow_nil => true, :accept => "1"))
end
|
Instance Method Details
#setup(klass) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/active_model/validations/acceptance.rb', line 16
def setup(klass)
attr_readers = attributes.reject { |name| klass.attribute_method?(name) }
attr_writers = attributes.reject { |name| klass.attribute_method?("#{name}=") }
klass.send(:attr_reader, *attr_readers)
klass.send(:attr_writer, *attr_writers)
end
|
#validate_each(record, attribute, value) ⇒ Object
10
11
12
13
14
|
# File 'lib/active_model/validations/acceptance.rb', line 10
def validate_each(record, attribute, value)
unless value == options[:accept]
record.errors.add(attribute, :accepted, options.except(:accept, :allow_nil))
end
end
|