Class: Terraspace::Hooks::Runner

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/terraspace/hooks/runner.rb

Instance Method Summary collapse

Methods included from Util::Pretty

#pretty_path, #pretty_time

Methods included from Util::Sure

#sure?

Methods included from Util::Logging

#logger

Constructor Details

#initialize(mod, hook) ⇒ Runner

Returns a new instance of Runner.



5
6
7
8
# File 'lib/terraspace/hooks/runner.rb', line 5

def initialize(mod, hook)
  @mod, @hook = mod, hook
  @execute = @hook["execute"]
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/terraspace/hooks/runner.rb', line 10

def run
  case @execute
  when String
    Terraspace::Shell.new(@mod, @execute, exit_on_fail: @hook["exit_on_fail"]).run
  when -> (e) { e.respond_to?(:public_instance_methods) && e.public_instance_methods.include?(:call) }
    @execute.new.call
  when -> (e) { e.respond_to?(:call) }
    @execute.call
  else
    logger.warn "WARN: execute option not set for hook: #{@hook.inspect}"
  end
end