Class: RouteAction

Inherits:
Object
  • Object
show all
Includes:
EventMachine::Deferrable
Defined in:
lib/cannon/route_action.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, action:, callback:) ⇒ RouteAction

Returns a new instance of RouteAction.



16
17
18
# File 'lib/cannon/route_action.rb', line 16

def initialize(app, action:, callback:)
  @app, @action, @callback = app, action, callback
end

Instance Attribute Details

#callback=(value) ⇒ Object (writeonly)

Sets the attribute callback

Parameters:

  • value

    the value to set the attribute callback to.



14
15
16
# File 'lib/cannon/route_action.rb', line 14

def callback=(value)
  @callback = value
end

Class Method Details

.controller(name, app) ⇒ Object



5
6
7
# File 'lib/cannon/route_action.rb', line 5

def controller(name, app)
  controllers[name] ||= Object.const_get(name).new(app)
end

.controllersObject



9
10
11
# File 'lib/cannon/route_action.rb', line 9

def controllers
  @controllers ||= {}
end

Instance Method Details

#last_actionObject



20
21
22
# File 'lib/cannon/route_action.rb', line 20

def last_action
  @callback.nil? ? self : @callback.last_action
end

#run(request, response, finish_proc) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cannon/route_action.rb', line 24

def run(request, response, finish_proc)
  next_proc = -> do
    if response.flushed?
      fail
      finish_proc.call
    else
      setup_callback
      succeed(request, response, finish_proc)
    end
  end

  if @action.is_a? Proc
    run_inline_action(request, response, next_proc)
  elsif @action.include? '#'
    run_controller_action(request, response, next_proc)
  else
    run_bound_action(request, response, next_proc)
  end
end