Class: Inprovise::TriggerRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/inprovise/trigger_runner.rb

Overview

Trigger runner for Inprovise

Author

Martin Corino

License

Distributes under the same license as Ruby

Instance Method Summary collapse

Constructor Details

#initialize(node, action_ref_with_args, skip_dependencies = false) ⇒ TriggerRunner

Returns a new instance of TriggerRunner.



7
8
9
10
11
12
13
# File 'lib/inprovise/trigger_runner.rb', line 7

def initialize(node, action_ref_with_args, skip_dependencies=false)
  @node = node
  @action_ref, @args = *parse_action_ref(action_ref_with_args)
  @log = Inprovise::Logger.new(@node, @action_ref)
  @skip_dependencies = skip_dependencies
  @index = Inprovise::ScriptIndex.default
end

Instance Method Details

#demonstrate(_, config = nil) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/inprovise/trigger_runner.rb', line 27

def demonstrate(_, config=nil)
  Inprovise.log.local("Demonstrating trigger #{@action_ref} for #{@node.to_s}")
  context = Inprovise::MockExecutionContext.new(@node, @log, @index, config)
  scr, action = context.resolve_action_ref(@action_ref)
  setup_configuration(scr, context) if scr
  context.trigger(scr, action, *@args)
end

#execute(_, config = nil) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/inprovise/trigger_runner.rb', line 19

def execute(_, config=nil)
  Inprovise.log.local("Triggering #{@action_ref} for #{@node.to_s}")
  context = Inprovise::ExecutionContext.new(@node, @log, @index, config)
  scr, action = context.resolve_action_ref(@action_ref)
  setup_configuration(scr, context) if scr
  context.trigger(scr, action, *@args)
end

#set_index(index) ⇒ Object



15
16
17
# File 'lib/inprovise/trigger_runner.rb', line 15

def set_index(index)
  @index = index
end