Class: ActiveModel::Validations::CollectionItemsValidator::ArrayAttributeGetter
- Inherits:
-
Object
- Object
- ActiveModel::Validations::CollectionItemsValidator::ArrayAttributeGetter
- Defined in:
- lib/active_model/validations/collection_items_validator/array_attribute_getter.rb
Overview
Decides how to get the value from array or other type of attribute.
Class Method Summary collapse
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(attribute, when_array:, when_normal:) ⇒ ArrayAttributeGetter
constructor
A new instance of ArrayAttributeGetter.
Constructor Details
#initialize(attribute, when_array:, when_normal:) ⇒ ArrayAttributeGetter
Returns a new instance of ArrayAttributeGetter.
11 12 13 14 15 |
# File 'lib/active_model/validations/collection_items_validator/array_attribute_getter.rb', line 11 def initialize(attribute, when_array:, when_normal:) @attribute = attribute @when_array = when_array @when_normal = when_normal end |
Class Method Details
.get(attribute, when_array:, when_normal:) ⇒ Object
6 7 8 |
# File 'lib/active_model/validations/collection_items_validator/array_attribute_getter.rb', line 6 def get(attribute, when_array:, when_normal:) new(attribute, when_array: when_array, when_normal: when_normal).get end |
Instance Method Details
#get ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/active_model/validations/collection_items_validator/array_attribute_getter.rb', line 17 def get if match_data when_array.call attibute_name, index else when_normal.call end end |