struct Amber::Router::ParamConstraints::Custom

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.cr

Constructors

Instance Method Summary

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

def self.new(label : String, &check : String -> Bool) #

[View source]

Instance Method Detail

def label : String #

[View source]
def matches?(segment : String) : Bool #
Description copied from module Amber::Router::ParamConstraint

Returns true when segment satisfies this rule.


[View source]
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.


[View source]