Class: Kawaii::Route
- Inherits:
-
Object
- Object
- Kawaii::Route
- Includes:
- MethodChain
- Defined in:
- lib/kawaii/route.rb
Overview
Matching and resolution for a single route.
Instance Attribute Summary
Attributes included from MethodChain
Instance Method Summary (collapse)
-
- (Route) initialize(scope, path, &block)
constructor
Create a Route object.
-
- (RouteHandler) match(env)
Tries to match the route against a Rack environment.
Methods included from MethodChain
Constructor Details
- (Route) initialize(scope, path, &block)
Create a Kawaii::Route object. consumed by Matcher.compile
10 11 12 13 14 |
# File 'lib/kawaii/route.rb', line 10 def initialize(scope, path, &block) self.parent_scope = scope @matcher = Matcher.compile(path, full_match: true) @block = block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Kawaii::MethodChain
Instance Method Details
- (RouteHandler) match(env)
Tries to match the route against a Rack environment. the route's handler block in on Kawaii::RouteHandler#call. Can be nil if no match found.
21 22 23 24 25 |
# File 'lib/kawaii/route.rb', line 21 def match(env) match = @matcher.match(env[Rack::PATH_INFO]) # puts "Route#match #{@matcher} #{env[Rack::PATH_INFO]} #{match.inspect}" RouteHandler.new(self, match.params, &@block) if match end |