Class: StrongerParameters::OrConstraint
- Inherits:
-
Constraint
- Object
- Constraint
- StrongerParameters::OrConstraint
- 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
-
#initialize(*constraints) ⇒ OrConstraint
constructor
A new instance of OrConstraint.
- #required? ⇒ Boolean
- #value(v) ⇒ Object
- #|(other) ⇒ Object
Methods inherited from Constraint
Constructor Details
#initialize(*constraints) ⇒ OrConstraint
Returns a new instance of OrConstraint.
35 36 37 |
# File 'lib/stronger_parameters/constraint.rb', line 35 def initialize(*constraints) @constraints = constraints end |
Instance Attribute Details
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
33 34 35 |
# File 'lib/stronger_parameters/constraint.rb', line 33 def constraints @constraints end |
Instance Method Details
#==(other) ⇒ Object
59 60 61 |
# File 'lib/stronger_parameters/constraint.rb', line 59 def ==(other) super && constraints == other.constraints end |
#required? ⇒ Boolean
63 64 65 |
# File 'lib/stronger_parameters/constraint.rb', line 63 def required? constraints.all?(&:required?) end |
#value(v) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/stronger_parameters/constraint.rb', line 39 def value(v) exception = nil constraints.each do |c| result = c.value(v) if result.is_a?(InvalidValue) exception ||= result else return result end end exception end |
#|(other) ⇒ Object
54 55 56 57 |
# File 'lib/stronger_parameters/constraint.rb', line 54 def |(other) constraints << other self end |