struct Athena::Framework::Arguments::Resolvers::Enum
inherits Struct
#
Handles resolving an Enum member from a string value that is stored in the request's ATH::Request#attributes
.
This resolver supports both numeric and string based parsing, returning a proper error response if the provided value does not map to any valid member.
require "athena"
enum Color
Red
Blue
Green
end
class ExampleController < ATH::Controller
@[ARTA::Get("/numeric/{color}")]
def get_color_numeric(color : Color) : Color
color
end
@[ARTA::Get("/string/{color}")]
def get_color_string(color : Color) : Color
color
end
end
ATH.run
# GET /numeric/1 # => "blue"
# GET /string/red # => "red"
Tip
Checkout ART::Requirement::Enum
for an easy way to restrict routing to an enum's members, or a subset of them.
Included modules
Athena::Framework::Arguments::Resolvers::Interface
Constructors#
Methods#
#resolve(request : ATH::Request, argument : ATH::Arguments::ArgumentMetadata)
#
Returns a value resolved from the provided request and argument.
#supports?(request : ATH::Request, argument : ATH::Arguments::ArgumentMetadata) : Bool
#
Returns true
if self
is able to resolve a value from the provided request and argument.