Class: ActiveModel::Validations::AcceptanceValidator
Do not use. This class is for internal use only.
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
ActiveModel::EachValidator
|
Defined in: | activemodel/lib/active_model/validations/acceptance.rb |
Class Method Summary
- .new(options) ⇒ AcceptanceValidator constructor
::ActiveModel::EachValidator
- Inherited
.new | Returns a new validator instance. |
::ActiveModel::Validator
- Inherited
Instance Attribute Summary
Instance Method Summary
- #validate_each(record, attribute, value)
- #acceptable_option?(value) ⇒ Boolean private
- #setup!(klass) private
::ActiveModel::EachValidator
- Inherited
#check_validity! | Hook method that gets called by the initializer allowing verification that the arguments supplied are valid. |
#validate | Performs validation on the supplied record. |
#validate_each | Override this method in subclasses with the validation logic, adding errors to the records #errors array where necessary. |
#prepare_value_for_validation |
::ActiveModel::Validator
- Inherited
Constructor Details
.new(options) ⇒ AcceptanceValidator
# File 'activemodel/lib/active_model/validations/acceptance.rb', line 6
def initialize( ) super({ allow_nil: true, accept: ["1", true] }.merge!( )) setup!( [:class]) end
Instance Method Details
#acceptable_option?(value) ⇒ Boolean
(private)
# File 'activemodel/lib/active_model/validations/acceptance.rb', line 23
def acceptable_option?(value) Array( [:accept]).include?(value) end
#setup!(klass) (private)
[ GitHub ]# File 'activemodel/lib/active_model/validations/acceptance.rb', line 18
def setup!(klass) define_attributes = LazilyDefineAttributes.new(attributes) klass.include(define_attributes) unless klass.included_modules.include?(define_attributes) end
#validate_each(record, attribute, value)
[ GitHub ]# File 'activemodel/lib/active_model/validations/acceptance.rb', line 11
def validate_each(record, attribute, value) unless acceptable_option?(value) record.errors.add(attribute, :accepted, ** .except(:accept, :allow_nil)) end end