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
Constructor Details
#initialize(*allowed) ⇒ EnumerationConstraint
Returns a new instance of EnumerationConstraint.
8 9 10 |
# File 'lib/stronger_parameters/constraints/enumeration_constraint.rb', line 8 def initialize(*allowed) @allowed = allowed end |
Instance Attribute Details
#allowed ⇒ Object (readonly)
Returns the value of attribute allowed.
6 7 8 |
# File 'lib/stronger_parameters/constraints/enumeration_constraint.rb', line 6 def allowed @allowed end |
Instance Method Details
#==(other) ⇒ Object
18 19 20 |
# File 'lib/stronger_parameters/constraints/enumeration_constraint.rb', line 18 def ==(other) super && allowed == other.allowed end |
#value(v) ⇒ Object
12 13 14 15 16 |
# File 'lib/stronger_parameters/constraints/enumeration_constraint.rb', line 12 def value(v) return v if allowed.include?(v) InvalidValue.new(v, "must be one of these: #{allowed.to_sentence}") end |