Class: StrongerParameters::ArrayConstraint
- Inherits:
-
Constraint
- Object
- Constraint
- StrongerParameters::ArrayConstraint
- Defined in:
- lib/stronger_parameters/constraints/array_constraint.rb
Instance Attribute Summary collapse
-
#item_constraint ⇒ Object
readonly
Returns the value of attribute item_constraint.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(item_constraint) ⇒ ArrayConstraint
constructor
A new instance of ArrayConstraint.
- #value(v) ⇒ Object
Methods inherited from Constraint
#&, #required, #required?, #|
Constructor Details
#initialize(item_constraint) ⇒ ArrayConstraint
Returns a new instance of ArrayConstraint.
9 10 11 |
# File 'lib/stronger_parameters/constraints/array_constraint.rb', line 9 def initialize(item_constraint) @item_constraint = item_constraint end |
Instance Attribute Details
#item_constraint ⇒ Object (readonly)
Returns the value of attribute item_constraint.
7 8 9 |
# File 'lib/stronger_parameters/constraints/array_constraint.rb', line 7 def item_constraint @item_constraint end |
Instance Method Details
#==(other) ⇒ Object
26 27 28 |
# File 'lib/stronger_parameters/constraints/array_constraint.rb', line 26 def ==(other) super && item_constraint == other.item_constraint end |
#value(v) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/stronger_parameters/constraints/array_constraint.rb', line 13 def value(v) if v.is_a?(Array) return v.map do |item| result = item_constraint.value(item) return result if result.is_a?(InvalidValue) result end end InvalidValue.new(v, "must be an array") end |