Class: StrongerParameters::EnumerationConstraint
- Inherits:
-
Constraint
- Object
- Constraint
- StrongerParameters::EnumerationConstraint
- Defined in:
- lib/stronger_parameters/constraints/enumeration_constraint.rb
Instance Attribute Summary collapse
-
#allowed ⇒ Object
readonly
Returns the value of attribute allowed.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(*allowed) ⇒ EnumerationConstraint
constructor
A new instance of EnumerationConstraint.
- #value(v) ⇒ Object
Methods inherited from Constraint
#&, #required, #required?, #|
Constructor Details
#initialize(*allowed) ⇒ EnumerationConstraint
Returns a new instance of EnumerationConstraint.
9 10 11 |
# File 'lib/stronger_parameters/constraints/enumeration_constraint.rb', line 9 def initialize(*allowed) @allowed = allowed end |
Instance Attribute Details
#allowed ⇒ Object (readonly)
Returns the value of attribute allowed.
7 8 9 |
# File 'lib/stronger_parameters/constraints/enumeration_constraint.rb', line 7 def allowed @allowed end |
Instance Method Details
#==(other) ⇒ Object
19 20 21 |
# File 'lib/stronger_parameters/constraints/enumeration_constraint.rb', line 19 def ==(other) super && allowed == other.allowed end |
#value(v) ⇒ Object
13 14 15 16 17 |
# File 'lib/stronger_parameters/constraints/enumeration_constraint.rb', line 13 def value(v) return v if allowed.include?(v) InvalidValue.new(v, "must be one of these: #{allowed.to_sentence}") end |