Class: LoadRunner::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/load_runner/runner.rb

Overview

Executes event handlers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Runner

Returns a new instance of Runner.



8
9
10
# File 'lib/load_runner/runner.rb', line 8

def initialize(opts)
  @opts = opts
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



5
6
7
# File 'lib/load_runner/runner.rb', line 5

def opts
  @opts
end

#responseObject

Returns the value of attribute response.



6
7
8
# File 'lib/load_runner/runner.rb', line 6

def response
  @response
end

Instance Method Details

#executeObject

Execute all matching handlers based on the input payload. This method populates the ‘#response` object, and returns true on success.



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

def execute
  set_environment_vars
  
  @response = opts.dup
  handlers = locate_handlers

  if handlers.empty?
    @response[:matching_handlers] = matching_handlers
    @response[:error] = "Could not find any handler to process this webhook. Please implement one of the 'matching_handlers'."
    return false
  else
    execute_all handlers
    @response[:executed_handlers] = handlers
    return true
  end
end

#handlers_dirObject



31
32
33
# File 'lib/load_runner/runner.rb', line 31

def handlers_dir
  @handlers_dir ||= 'handlers'
end

#handlers_dir=(path) ⇒ Object



35
36
37
# File 'lib/load_runner/runner.rb', line 35

def handlers_dir=(path)
  @handlers_dir = path
end