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.
- #value(v) ⇒ Object
- #|(other) ⇒ Object
Methods inherited from Constraint
Constructor Details
#initialize(*constraints) ⇒ OrConstraint
Returns a new instance of OrConstraint.
26 27 28 |
# File 'lib/stronger_parameters/constraint.rb', line 26 def initialize(*constraints) @constraints = constraints end |
Instance Attribute Details
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
24 25 26 |
# File 'lib/stronger_parameters/constraint.rb', line 24 def constraints @constraints end |
Instance Method Details
#==(other) ⇒ Object
50 51 52 |
# File 'lib/stronger_parameters/constraint.rb', line 50 def ==(other) super && constraints == other.constraints end |
#value(v) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/stronger_parameters/constraint.rb', line 30 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
45 46 47 48 |
# File 'lib/stronger_parameters/constraint.rb', line 45 def |(other) constraints << other self end |