class Dry::Types::Enum

def call(input)

Returns:
  • (Object) -

Parameters:
  • input (Object) --
def call(input)
  value =
    if values.include?(input)
      input
    elsif mapping.key?(input)
      mapping[input]
    end
  type[value || input]
end

def initialize(type, options)

Options Hash: (**options)
  • :values (Array) --

Parameters:
  • options (Hash) --
  • type (Definition) --
def initialize(type, options)
  super
  @values = options.fetch(:values).freeze
  @values.each(&:freeze)
  @mapping = values.each_with_object({}) { |v, h| h[values.index(v)] = v }.freeze
end