struct
Amber::Router::ParamConstraints::Custom
- Amber::Router::ParamConstraints::Custom
- Struct
- Value
- Object
Overview
Matches a segment for which the given block returns true. Use it for a
one-off rule; a rule used in several places reads better as its own type
that includes Amber::Router::ParamConstraint.
The block runs on every request that reaches the route's segment, so keep it linear in the segment's length.
json_file = Amber::Router::ParamConstraints::Custom.new("json_file") do |segment|
segment.ends_with?(".json")
end
get "/files/:name", FilesController, :show, {"name" => json_file}
Included Modules
Defined in:
amber/router/param_constraints/custom.crConstructors
Instance Method Summary
- #label : String
-
#matches?(segment : String) : Bool
Returns
truewhen segment satisfies this rule. -
#to_s(io : IO) : Nil
Writes the short label that route listings and
Route#to_jsonshow for this rule.
Instance methods inherited from module Amber::Router::ParamConstraint
matches?(segment : String) : Bool
matches?,
matches_span?(path : String, byte_offset : Int32, bytesize : Int32) : Bool
matches_span?,
to_s(io : IO) : Nil
to_s
Constructor Detail
Instance Method Detail
Description copied from module Amber::Router::ParamConstraint
Returns true when segment satisfies this rule.
def to_s(io : IO) : Nil
#
Description copied from module Amber::Router::ParamConstraint
Writes the short label that route listings and Route#to_json show for
this rule.