Class: Loom::Pattern::Reference::RunContext

Inherits:
Object
  • Object
show all
Defined in:
lib/loom/pattern/reference.rb

Overview

A small class to bind the unbound_method to and provide context in the case of errors.

Instance Method Summary collapse

Constructor Details

#initialize(pattern, definition_ctx) ⇒ RunContext

Returns a new instance of RunContext.



48
49
50
51
# File 'lib/loom/pattern/reference.rb', line 48

def initialize(pattern, definition_ctx)
  @pattern = pattern
  @definition_ctx = definition_ctx
end

Instance Method Details

#run(shell_api, fact_set) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/loom/pattern/reference.rb', line 53

def run(shell_api, fact_set)
  before_hooks = @definition_ctx.before_hooks
  after_hooks = @definition_ctx.after_hooks

  begin
    Loom.log.debug1(self) { "before hooks => #{before_hooks}"}
    before_hooks.each do |hook|
      Loom.log.debug2(self) { "executing before hook => #{hook}"}
      instance_exec shell_api, fact_set, &hook.block
    end

    # This is the entry point into calling patterns.
    apply_pattern shell_api, fact_set
  ensure
    Loom.log.debug1(self) { "after hooks => #{after_hooks}" }
    after_hooks.each do |hook|
      Loom.log.debug2(self) { "executing after hook => #{hook}"}
      instance_exec shell_api, fact_set, &hook.block
    end
  end
end