Class: Rory::RouteMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rory/route_mapper.rb

Overview

Route mapper, used to convert the entries in ‘config/routes.rb’ into a routing table for use by the dispatcher.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRouteMapper

Returns a new instance of RouteMapper.



13
14
15
16
# File 'lib/rory/route_mapper.rb', line 13

def initialize
  @routes = []
  @scope_options = {}
end

Class Method Details

.set_routes(&block) ⇒ Object



6
7
8
9
10
# File 'lib/rory/route_mapper.rb', line 6

def set_routes(&block)
  mapper = new
  mapper.instance_exec(&block)
  mapper.routing_map
end

Instance Method Details

#match(mask, options = {}) ⇒ Object



29
30
31
32
33
# File 'lib/rory/route_mapper.rb', line 29

def match(mask, options = {})
  options.merge!(@scope_options)
  options[:to] ||= mask.split('/').first
  @routes << Route.new(mask, options)
end

#routing_mapObject



18
19
20
# File 'lib/rory/route_mapper.rb', line 18

def routing_map
  @routes
end

#scope(options = {}, &block) ⇒ Object



22
23
24
25
26
27
# File 'lib/rory/route_mapper.rb', line 22

def scope(options = {}, &block)
  previous_options, @scope_options =
    @scope_options, @scope_options.merge(options)
  yield
  @scope_options = previous_options
end