Class: StrongerParameters::AndConstraint

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Constraint

#required, #|

Constructor Details

#initialize(*constraints) ⇒ AndConstraint

Returns a new instance of AndConstraint.



70
71
72
# File 'lib/stronger_parameters/constraint.rb', line 70

def initialize(*constraints)
  @constraints = constraints
end

Instance Attribute Details

#constraintsObject (readonly)

Returns the value of attribute constraints.



68
69
70
# File 'lib/stronger_parameters/constraint.rb', line 68

def constraints
  @constraints
end

Instance Method Details

#&(other) ⇒ Object



82
83
84
85
# File 'lib/stronger_parameters/constraint.rb', line 82

def &(other)
  constraints << other
  self
end

#==(other) ⇒ Object



87
88
89
# File 'lib/stronger_parameters/constraint.rb', line 87

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

#required?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/stronger_parameters/constraint.rb', line 91

def required?
  constraints.any?(&:required?)
end

#value(v) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/stronger_parameters/constraint.rb', line 74

def value(v)
  constraints.each do |c|
    v = c.value(v)
    return v if v.is_a?(InvalidValue)
  end
  v
end