Class: Rack::Mount::RouteSet
- Inherits:
-
Object
- Object
- Rack::Mount::RouteSet
- Extended by:
- Mixover
- Includes:
- Generation::RouteSet, Rack::Mount::Recognition::CodeGeneration, Rack::Mount::Recognition::RouteSet
- Defined in:
- lib/rack/mount/route_set.rb
Constant Summary
Constants included from Rack::Mount::Recognition::RouteSet
Rack::Mount::Recognition::RouteSet::EXPECT, Rack::Mount::Recognition::RouteSet::PATH_INFO
Instance Attribute Summary
Attributes included from Rack::Mount::Recognition::RouteSet
Class Method Summary collapse
-
.new_without_optimizations(*args, &block) ⇒ Object
Initialize a new RouteSet without optimizations.
Instance Method Summary collapse
-
#add_route(app, conditions = {}, defaults = {}, name = nil) ⇒ Object
Builder method to add a route to the set.
-
#call(env) ⇒ Object
See
Recognition::RouteSet#call
. -
#freeze ⇒ Object
Finalizes the set and builds optimized data structures.
-
#generate(*args) ⇒ Object
See
Generation::RouteSet#generate
. -
#initialize(options = {}, &block) ⇒ RouteSet
constructor
Basic RouteSet initializer.
-
#length ⇒ Object
Number of routes in the set.
-
#rehash ⇒ Object
:nodoc:.
-
#url(*args) ⇒ Object
See
Generation::RouteSet#url
.
Methods included from Mixover
include, new, new_with_module, new_without_module
Methods included from Rack::Mount::Recognition::CodeGeneration
Methods included from Rack::Mount::Recognition::RouteSet
Constructor Details
#initialize(options = {}, &block) ⇒ RouteSet
Basic RouteSet initializer.
If a block is given, the set is yielded and finalized.
See other aspects for other valid options:
-
Generation::RouteSet.new
-
Recognition::RouteSet.new
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rack/mount/route_set.rb', line 25 def initialize( = {}, &block) @request_class = .delete(:request_class) || Rack::Request @routes = [] expire! if block_given? yield self rehash end end |
Class Method Details
.new_without_optimizations(*args, &block) ⇒ Object
Initialize a new RouteSet without optimizations
14 15 16 |
# File 'lib/rack/mount/route_set.rb', line 14 def self.new_without_optimizations(*args, &block) new_without_module(Recognition::CodeGeneration, *args, &block) end |
Instance Method Details
#add_route(app, conditions = {}, defaults = {}, name = nil) ⇒ Object
Builder method to add a route to the set
app
-
A valid Rack app to call if the conditions are met.
conditions
-
A hash of conditions to match against. Conditions may be expressed as strings or regexps to match against.
defaults
-
A hash of values that always gets merged in
name
-
Symbol identifier for the route used with named route generations
45 46 47 48 49 50 |
# File 'lib/rack/mount/route_set.rb', line 45 def add_route(app, conditions = {}, defaults = {}, name = nil) route = Route.new(self, app, conditions, defaults, name) @routes << route expire! route end |
#call(env) ⇒ Object
See Recognition::RouteSet#call
53 54 55 |
# File 'lib/rack/mount/route_set.rb', line 53 def call(env) raise NotImplementedError end |
#freeze ⇒ Object
Finalizes the set and builds optimized data structures. You must freeze the set before you can use call
and url
. So remember to call freeze after you are done adding routes.
78 79 80 81 82 83 84 85 86 |
# File 'lib/rack/mount/route_set.rb', line 78 def freeze unless frozen? rehash @routes.each { |route| route.freeze } @routes.freeze end super end |
#generate(*args) ⇒ Object
See Generation::RouteSet#generate
63 64 65 |
# File 'lib/rack/mount/route_set.rb', line 63 def generate(*args) raise NotImplementedError end |
#length ⇒ Object
Number of routes in the set
68 69 70 |
# File 'lib/rack/mount/route_set.rb', line 68 def length @routes.length end |
#rehash ⇒ Object
:nodoc:
72 73 |
# File 'lib/rack/mount/route_set.rb', line 72 def rehash #:nodoc: end |
#url(*args) ⇒ Object
See Generation::RouteSet#url
58 59 60 |
# File 'lib/rack/mount/route_set.rb', line 58 def url(*args) raise NotImplementedError end |