Class: SimpleController::Router::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_controller/router/route.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller_path, action_name) ⇒ Route

Returns a new instance of Route.



6
7
8
# File 'lib/simple_controller/router/route.rb', line 6

def initialize(controller_path, action_name)
  @controller_path, @action_name = controller_path, action_name
end

Instance Attribute Details

#action_nameObject (readonly)

Returns the value of attribute action_name.



4
5
6
# File 'lib/simple_controller/router/route.rb', line 4

def action_name
  @action_name
end

#controller_pathObject (readonly)

Returns the value of attribute controller_path.



4
5
6
# File 'lib/simple_controller/router/route.rb', line 4

def controller_path
  @controller_path
end

Instance Method Details

#call(params, context, controller_path_block) ⇒ Object



10
11
12
13
14
15
# File 'lib/simple_controller/router/route.rb', line 10

def call(params, context, controller_path_block)
  controller_class = controller_path_block ? controller_path_block.call(controller_path) : "#{controller_path}_controller".classify.constantize

  params = { 'controller' => controller_path, 'action' => action_name }.reverse_merge(params)
  controller_class.call action_name, params, context
end