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
11
# File 'lib/load_runner/runner.rb', line 8

def initialize(opts)
  @handlers_dir = 'handlers'
  @opts = opts
end

Instance Attribute Details

#handlers_dirObject

Returns the value of attribute handlers_dir.



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

def handlers_dir
  @handlers_dir
end

#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.



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

def execute
  set_environment_vars

  @response = opts.dup
  handlers = locate_handlers
  @response[:matching_handlers] = matching_handlers

  if handlers.empty?
    @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