Class: YleTf::TfHook::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/yle_tf/tf_hook/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, hook_env) ⇒ Runner

Returns a new instance of Runner.



9
10
11
12
# File 'lib/yle_tf/tf_hook/runner.rb', line 9

def initialize(config, hook_env)
  @config = config
  @hook_env = hook_env
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/yle_tf/tf_hook/runner.rb', line 7

def config
  @config
end

#hook_envObject (readonly)

Returns the value of attribute hook_env.



7
8
9
# File 'lib/yle_tf/tf_hook/runner.rb', line 7

def hook_env
  @hook_env
end

Instance Method Details

#hook_confs(hook_type) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/yle_tf/tf_hook/runner.rb', line 30

def hook_confs(hook_type)
  config.fetch('hooks', hook_type).select do |hook|
    if hook['envs'] && !hook['envs'].include?(tf_env)
      Logger.debug("Skipping hook '#{hook['description']}' in env '#{tf_env}'")
      false
    else
      true
    end
  end
end

#hook_files(hook_type) ⇒ Object



41
42
43
44
45
# File 'lib/yle_tf/tf_hook/runner.rb', line 41

def hook_files(hook_type)
  Dir.glob("tf_hooks/#{hook_type}/*").select do |file|
    File.executable?(file) && !File.directory?(file)
  end
end

#hooks(hook_type) ⇒ Object



25
26
27
28
# File 'lib/yle_tf/tf_hook/runner.rb', line 25

def hooks(hook_type)
  hook_confs(hook_type).map { |conf| TfHook.from_config(conf, tf_env) } +
    hook_files(hook_type).map { |file| TfHook.from_file(file) }
end

#run(hook_type) ⇒ Object



18
19
20
21
22
23
# File 'lib/yle_tf/tf_hook/runner.rb', line 18

def run(hook_type)
  Logger.debug("Running #{hook_type} hooks")
  hooks(hook_type).each do |hook|
    hook.run(hook_env)
  end
end

#tf_envObject



14
15
16
# File 'lib/yle_tf/tf_hook/runner.rb', line 14

def tf_env
  @tf_env ||= config.tf_env
end