Class: Dandy::Chain

Inherits:
Object
  • Object
show all
Defined in:
lib/dandy/chain.rb

Instance Method Summary collapse

Constructor Details

#initialize(container, dandy_config, commands, last_command, catch_command = nil) ⇒ Chain

Returns a new instance of Chain.



5
6
7
8
9
10
11
# File 'lib/dandy/chain.rb', line 5

def initialize(container, dandy_config, commands, last_command, catch_command = nil)
  @commands = commands
  @last_command = last_command
  @container = container
  @catch_command = catch_command
  @async_timeout = dandy_config[:action][:async_timeout]
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dandy/chain.rb', line 13

def execute
  if @catch_command.nil?
    run_commands
  else
    begin
      run_commands
    rescue Exception => error
      @container
        .register_instance(error, :dandy_error)
        .using_lifetime(:scope)
        .bound_to(:dandy_request)

      action = @container.resolve(@catch_command.name.to_sym)
      action.call
    end
  end
end