Class: ParamsReady::Value::EnumConstraint

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

Instance Attribute Summary

Attributes inherited from Constraint

#condition

Instance Method Summary collapse

Methods inherited from Constraint

build, #clamp?, instance, register

Methods included from Extensions::Registry

#human_string, #registry

Constructor Details

#initialize(cond, *args, **opts) ⇒ EnumConstraint

Returns a new instance of EnumConstraint.

Raises:



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_messageObject



107
108
109
# File 'lib/params_ready/value/constraint.rb', line 107

def error_message
  'not in enum'
end

#valid?(input) ⇒ Boolean

Returns:

  • (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