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



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

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

#value(v) ⇒ Object



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

def value(v)
  exception = nil

  constraints.each do |c|
    begin
      return c.value(v)
    rescue InvalidParameter => e
      exception ||= e
    end
  end

  raise exception
end

#|(other) ⇒ Object



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

def |(other)
  constraints << other
  self
end