Class: Journey::Routes
- Inherits:
-
Object
- Object
- Journey::Routes
- Includes:
- Enumerable
- Defined in:
- lib/journey/routes.rb
Overview
The Routing table. Contains all routes for a system. Routes can be added to the table by calling Routes#add_route
Instance Attribute Summary collapse
-
#named_routes ⇒ Object
readonly
Returns the value of attribute named_routes.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
-
#add_route(app, path, conditions, defaults, name = nil) ⇒ Object
Add a route to the routing table.
- #ast ⇒ Object
- #clear ⇒ Object
- #each(&block) ⇒ Object
-
#initialize ⇒ Routes
constructor
A new instance of Routes.
- #last ⇒ Object
- #length ⇒ Object (also: #size)
- #partitioned_routes ⇒ Object
- #simulator ⇒ Object
Constructor Details
#initialize ⇒ Routes
Returns a new instance of Routes.
10 11 12 13 14 15 16 |
# File 'lib/journey/routes.rb', line 10 def initialize @routes = [] @named_routes = {} @ast = nil @partitioned_routes = nil @simulator = nil end |
Instance Attribute Details
#named_routes ⇒ Object (readonly)
Returns the value of attribute named_routes.
8 9 10 |
# File 'lib/journey/routes.rb', line 8 def named_routes @named_routes end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
8 9 10 |
# File 'lib/journey/routes.rb', line 8 def routes @routes end |
Instance Method Details
#add_route(app, path, conditions, defaults, name = nil) ⇒ Object
Add a route to the routing table.
58 59 60 61 62 63 64 65 66 |
# File 'lib/journey/routes.rb', line 58 def add_route app, path, conditions, defaults, name = nil route = Route.new(name, app, path, conditions, defaults) route.precedence = routes.length routes << route named_routes[name] = route if name clear_cache! route end |
#ast ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/journey/routes.rb', line 41 def ast return @ast if @ast return if partitioned_routes.first.empty? asts = partitioned_routes.first.map { |r| r.ast } @ast = Nodes::Or.new(asts) end |
#clear ⇒ Object
31 32 33 |
# File 'lib/journey/routes.rb', line 31 def clear routes.clear end |
#each(&block) ⇒ Object
27 28 29 |
# File 'lib/journey/routes.rb', line 27 def each(&block) routes.each(&block) end |
#last ⇒ Object
23 24 25 |
# File 'lib/journey/routes.rb', line 23 def last @routes.last end |
#length ⇒ Object Also known as: size
18 19 20 |
# File 'lib/journey/routes.rb', line 18 def length @routes.length end |
#partitioned_routes ⇒ Object
35 36 37 38 39 |
# File 'lib/journey/routes.rb', line 35 def partitioned_routes @partitioned_routes ||= routes.partition { |r| r.path.anchored && r.ast.grep(Nodes::Symbol).all? { |n| n.default_regexp? } } end |
#simulator ⇒ Object
49 50 51 52 53 54 |
# File 'lib/journey/routes.rb', line 49 def simulator return @simulator if @simulator gtg = GTG::Builder.new(ast).transition_table @simulator = GTG::Simulator.new gtg end |