class Highway::Steps::Types::Any

This class represents any parameter type. It can be used in parameters which should not perform any type checking.

Public Class Methods

new(validate: nil) click to toggle source

Initialize an instance.

@param validate [Proc] A custom value validation block.

# File lib/highway/steps/types/any.rb, line 19
def initialize(validate: nil)
  @validate = validate
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 [Object, nil]

# File lib/highway/steps/types/any.rb, line 31
def typecheck(value)
  value
end
typecheck_and_validate(value) click to toggle source

Typecheck and validate the value at the same time.

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

@param value [Object] A value.

@return [Object, nil]

# File lib/highway/steps/types/any.rb, line 56
def typecheck_and_validate(value)
  typechecked = typecheck(value)
  typechecked if !typechecked.nil? && validate(typechecked)
end
validate(value) click to toggle source

Validate the typechecked value against a custom validation block.

This method returns `true` if value is valid or `false` if value is invalid.

@param value [Object] A value.

@return [Boolean]

# File lib/highway/steps/types/any.rb, line 43
def validate(value)
  return true if @validate == nil
  @validate.call(value)
end