struct Athena::Routing::Requirement::Enum(EnumType)
- Athena::Routing::Requirement::Enum(EnumType)
- Struct
- Value
- Object
Overview
Provides an easier way to define a [route requirement][Athena::Routing::Route--parameter-validation] for all, or a subset of, Enum members.
For example:
require "athena"
enum Color
Red
Blue
Green
Black
end
class ExampleController < ATH::Controller
@[ARTA::Get(
"/color/{color}",
requirements: {"color" => ART::Requirement::Enum(Color).new},
)]
def get_color(color : Color) : Color
color
end
@[ARTA::Get(
"/rgb-color/{color}",
requirements: {"color" => ART::Requirement::Enum(Color).new(:red, :green, :blue)},
)]
def get_rgb_color(color : Color) : Color
color
end
end
ATH.run
# GET /color/red # => "red"
# GET /color/pink # => 404
#
# GET /rgb-color/red # => "red"
# GET /rgb-color/green # => "green"
# GET /rgb-color/blue # => "blue"
# GET /rgb-color/black # => 404
NOTE This type ONLY supports the string representation of enum members.
Defined in:
requirement/enum.crConstructors
Instance Method Summary
-
#members : Set(EnumType) | Nil
Returns the set of allowed enum members, or
nil
if all members are allowed.
Constructor Detail
Instance Method Detail
def members : Set(EnumType) | Nil
#
Returns the set of allowed enum members, or nil
if all members are allowed.