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.
34 35 36 |
# File 'lib/stronger_parameters/constraint.rb', line 34 def initialize(*constraints) @constraints = constraints end |
Instance Attribute Details
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
32 33 34 |
# File 'lib/stronger_parameters/constraint.rb', line 32 def constraints @constraints end |
Instance Method Details
#==(other) ⇒ Object
58 59 60 |
# File 'lib/stronger_parameters/constraint.rb', line 58 def ==(other) super && constraints == other.constraints end |
#required? ⇒ Boolean
62 63 64 |
# File 'lib/stronger_parameters/constraint.rb', line 62 def required? constraints.all?(&:required?) end |
#value(v) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/stronger_parameters/constraint.rb', line 38 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
53 54 55 56 |
# File 'lib/stronger_parameters/constraint.rb', line 53 def |(other) constraints << other self end |