Class: StrongerParameters::OrConstraint

Inherits:
Constraint
  • Object
show all
Defined in:
lib/stronger_parameters/constraints.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Constraint

#&

Constructor Details

#initialize(*constraints) ⇒ OrConstraint

Returns a new instance of OrConstraint.



25
26
27
# File 'lib/stronger_parameters/constraints.rb', line 25

def initialize(*constraints)
  @constraints = constraints
end

Instance Attribute Details

#constraintsObject (readonly)

Returns the value of attribute constraints.



23
24
25
# File 'lib/stronger_parameters/constraints.rb', line 23

def constraints
  @constraints
end

Instance Method Details

#==(other) ⇒ Object



49
50
51
# File 'lib/stronger_parameters/constraints.rb', line 49

def ==(other)
  super && constraints == other.constraints
end

#value(v) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/stronger_parameters/constraints.rb', line 29

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



44
45
46
47
# File 'lib/stronger_parameters/constraints.rb', line 44

def |(other)
  constraints << other
  self
end