class Terraspace::Hooks::Builder
Attributes
name[RW]
IE: dsl_file: config/hooks/terraform.rb
Public Class Methods
new(mod, file, name)
click to toggle source
# File lib/terraspace/hooks/builder.rb, line 10 def initialize(mod, file, name) @mod, @file, @name = mod, file, name @hooks = {before: {}, after: {}} end
Public Instance Methods
build()
click to toggle source
# File lib/terraspace/hooks/builder.rb, line 15 def build evaluate_file("#{Terraspace.root}/config/hooks/#{@file}") evaluate_file("#{@mod.root}/config/hooks/#{@file}") @hooks.deep_stringify_keys! end
run?(hook)
click to toggle source
# File lib/terraspace/hooks/builder.rb, line 47 def run?(hook) !!hook["execute"] end
run_each_hook(type)
click to toggle source
# File lib/terraspace/hooks/builder.rb, line 30 def run_each_hook(type) hooks = @hooks.dig(type, @name) || [] hooks.each do |hook| run_hook(type, hook) end end
run_hook(type, hook)
click to toggle source
# File lib/terraspace/hooks/builder.rb, line 37 def run_hook(type, hook) return unless run?(hook) command = File.basename(@file).sub('.rb','') # IE: terraform or terraspace id = "#{command} #{type} #{@name}" label = " label: #{hook["label"]}" if hook["label"] logger.info "Hook: Running #{id} hook.#{label}".color(:cyan) Runner.new(@mod, hook).run end
run_hooks() { || ... }
click to toggle source
# File lib/terraspace/hooks/builder.rb, line 22 def run_hooks build run_each_hook("before") out = yield if block_given? run_each_hook("after") out end