Class: StrongerParameters::AndConstraint
- Inherits:
-
Constraint
- Object
- Constraint
- StrongerParameters::AndConstraint
- Defined in:
- lib/stronger_parameters/constraint.rb
Instance Attribute Summary collapse
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
Instance Method Summary collapse
- #&(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(*constraints) ⇒ AndConstraint
constructor
A new instance of AndConstraint.
- #required? ⇒ Boolean
- #value(v) ⇒ Object
Methods inherited from Constraint
Constructor Details
#initialize(*constraints) ⇒ AndConstraint
Returns a new instance of AndConstraint.
71 72 73 |
# File 'lib/stronger_parameters/constraint.rb', line 71 def initialize(*constraints) @constraints = constraints end |
Instance Attribute Details
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
69 70 71 |
# File 'lib/stronger_parameters/constraint.rb', line 69 def constraints @constraints end |
Instance Method Details
#&(other) ⇒ Object
83 84 85 86 |
# File 'lib/stronger_parameters/constraint.rb', line 83 def &(other) constraints << other self end |
#==(other) ⇒ Object
88 89 90 |
# File 'lib/stronger_parameters/constraint.rb', line 88 def ==(other) super && constraints == other.constraints end |
#required? ⇒ Boolean
92 93 94 |
# File 'lib/stronger_parameters/constraint.rb', line 92 def required? constraints.any?(&:required?) end |
#value(v) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/stronger_parameters/constraint.rb', line 75 def value(v) constraints.each do |c| v = c.value(v) return v if v.is_a?(InvalidValue) end v end |