Class: ParamsReady::Value::EnumConstraint
- Inherits:
-
Constraint
- Object
- Constraint
- ParamsReady::Value::EnumConstraint
- Defined in:
- lib/params_ready/value/constraint.rb
Instance Attribute Summary
Attributes inherited from Constraint
Instance Method Summary collapse
- #error_message ⇒ Object
-
#initialize(cond, *args, **opts) ⇒ EnumConstraint
constructor
A new instance of EnumConstraint.
- #valid?(input) ⇒ Boolean
Methods inherited from Constraint
build, #clamp?, instance, register
Methods included from Extensions::Registry
Constructor Details
#initialize(cond, *args, **opts) ⇒ EnumConstraint
Returns a new instance of EnumConstraint.
92 93 94 95 96 97 |
# File 'lib/params_ready/value/constraint.rb', line 92 def initialize(cond, *args, **opts) raise ParamsReadyError, "Expected Set or Array, got: " + cond.class.name unless cond.is_a?(Set) || cond.is_a?(Array) super cond, *args, **opts end |
Instance Method Details
#error_message ⇒ Object
107 108 109 |
# File 'lib/params_ready/value/constraint.rb', line 107 def 'not in enum' end |
#valid?(input) ⇒ Boolean
99 100 101 102 103 104 105 |
# File 'lib/params_ready/value/constraint.rb', line 99 def valid?(input) if input.is_a?(String) @condition.include?(input) || @condition.include?(input.to_sym) else @condition.include?(input) end end |