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.



11
12
13
14
# File 'lib/yle_tf/tf_hook/runner.rb', line 11

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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#hook_envObject (readonly)

Returns the value of attribute hook_env.



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

def hook_env
  @hook_env
end

Instance Method Details

#hook_confs(hook_type) ⇒ Object



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

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



43
44
45
46
47
# File 'lib/yle_tf/tf_hook/runner.rb', line 43

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



27
28
29
30
# File 'lib/yle_tf/tf_hook/runner.rb', line 27

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



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

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

#tf_envObject



16
17
18
# File 'lib/yle_tf/tf_hook/runner.rb', line 16

def tf_env
  @tf_env ||= config.tf_env
end