class Highway::Steps::Types::Enum

This class represents an enum parameter type. It can be used in parameters which have a finite set of valid values.

Public Class Methods

new(*values) click to toggle source

Initialize an instance.

@param *values [String] Allowed enum values.

Calls superclass method Highway::Steps::Types::Any::new
# File lib/highway/steps/types/enum.rb, line 22
def initialize(*values)
  super(validate: nil)
  @values = values
end

Public Instance Methods

typecheck(value) click to toggle source

Typecheck and coerce a value if possible.

This method returns a typechecked and coerced value or `nil` if value has invalid type and can't be coerced.

@param value [Object] A value.

@return [String, nil]

Calls superclass method Highway::Steps::Types::String#typecheck
# File lib/highway/steps/types/enum.rb, line 35
def typecheck(value)
  typechecked = super(value)
  typechecked if !typechecked.nil? && @values.include?(typechecked)
end