Class: Lennarb::Routes
- Inherits:
-
Object
- Object
- Lennarb::Routes
- Defined in:
- lib/lennarb/routes.rb
Overview
Routes class for managing application routes
Instance Method Summary collapse
-
#freeze ⇒ self
Freeze the routes to prevent further modification.
-
#frozen? ⇒ Boolean
Check if the routes are frozen.
-
#initialize ⇒ Routes
constructor
Initialize a new Routes instance.
-
#match_route(parts, http_method) ⇒ Array(Proc, Hash)?
Match a route with the given path parts and HTTP method.
-
#merge!(other) ⇒ self
private
Copy the routes from another Routes instance into this one.
-
#root(&block) ⇒ void
Define the root route (GET /).
Constructor Details
#initialize ⇒ Routes
Initialize a new Routes instance
8 9 10 11 |
# File 'lib/lennarb/routes.rb', line 8 def initialize @store = RouteNode.new @frozen = false end |
Instance Method Details
#freeze ⇒ self
Freeze the routes to prevent further modification.
Freezes the whole tree, not only the root, so a frozen copy really is immutable.
57 58 59 60 61 |
# File 'lib/lennarb/routes.rb', line 57 def freeze @frozen = true deep_freeze(@store) self end |
#frozen? ⇒ Boolean
Check if the routes are frozen
66 67 68 |
# File 'lib/lennarb/routes.rb', line 66 def frozen? @frozen end |
#match_route(parts, http_method) ⇒ Array(Proc, Hash)?
Match a route with the given path parts and HTTP method
34 35 36 |
# File 'lib/lennarb/routes.rb', line 34 def match_route(parts, http_method) @store.match_route(parts, http_method) end |
#merge!(other) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Copy the routes from another Routes instance into this one.
The copy is deep: node objects are rebuilt rather than shared, so routes registered on the source afterwards cannot leak into this instance.
46 47 48 49 |
# File 'lib/lennarb/routes.rb', line 46 def merge!(other) @store.merge!(deep_copy(other.store)) self end |
#root(&block) ⇒ void
This method returns an undefined value.
Define the root route (GET /)
25 26 27 |
# File 'lib/lennarb/routes.rb', line 25 def root(&block) get("/", &block) end |