module SimpleController::Router::Core

Attributes

controller_path_block[R]
params[R]
route_mapping[R]
route_path[R]

Public Class Methods

new() click to toggle source
# File lib/simple_controller/router/core.rb, line 12
def initialize
  @route_mapping = {}
end

Public Instance Methods

add_route(route_path, controller_path, action) click to toggle source
# 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={}) click to toggle source
# 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) click to toggle source
# File lib/simple_controller/router/core.rb, line 31
def draw(&block)
  mapper = Mapper.new(self)
  mapper.instance_eval(&block)
  self
end
parse_controller_path(&block) click to toggle source
# File lib/simple_controller/router/core.rb, line 41
def parse_controller_path(&block)
  @controller_path_block = block
end
route_paths() click to toggle source
# File lib/simple_controller/router/core.rb, line 27
def route_paths
  route_mapping.keys
end

Protected Instance Methods

_call(route) click to toggle source
# File lib/simple_controller/router/core.rb, line 46
def _call(route)
  route.call params, controller_path_block
end