Module: SimpleController::Router::Core
- Extended by:
- ActiveSupport::Concern
- Included in:
- SimpleController::Router
- Defined in:
- lib/simple_controller/router/core.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #add_route(route_path, controller_path, action) ⇒ Object
- #call(route_path, params = {}) ⇒ Object
- #draw(&block) ⇒ Object
- #initialize ⇒ Object
- #parse_controller_path(&block) ⇒ Object
- #route_paths ⇒ Object
Instance Method Details
#add_route(route_path, controller_path, action) ⇒ Object
37 38 39 |
# File 'lib/simple_controller/router/core.rb', line 37 def add_route(route_path, controller_path, action) @route_mapping[route_path] = Route.new(controller_path, action) end |
#call(route_path, params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/simple_controller/router/core.rb', line 16 def call(route_path, params={}) @route_path = route_path.to_s @params = params route = @route_mapping[@route_path] raise "#{self.class} route for '#{@route_path}' not found" unless route _call(route) ensure @route_path = @params = nil end |
#draw(&block) ⇒ Object
31 32 33 34 35 |
# File 'lib/simple_controller/router/core.rb', line 31 def draw(&block) mapper = Mapper.new(self) mapper.instance_eval(&block) self end |
#initialize ⇒ Object
12 13 14 |
# File 'lib/simple_controller/router/core.rb', line 12 def initialize @route_mapping = {} end |
#parse_controller_path(&block) ⇒ Object
41 42 43 |
# File 'lib/simple_controller/router/core.rb', line 41 def parse_controller_path(&block) @controller_path_block = block end |
#route_paths ⇒ Object
27 28 29 |
# File 'lib/simple_controller/router/core.rb', line 27 def route_paths route_mapping.keys end |