Class: YleTf::TfHook::Runner
- Inherits:
-
Object
- Object
- YleTf::TfHook::Runner
- Defined in:
- lib/yle_tf/tf_hook/runner.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#hook_env ⇒ Object
readonly
Returns the value of attribute hook_env.
Instance Method Summary collapse
- #hook_confs(hook_type) ⇒ Object
- #hook_files(hook_type) ⇒ Object
- #hooks(hook_type) ⇒ Object
-
#initialize(config, hook_env) ⇒ Runner
constructor
A new instance of Runner.
- #run(hook_type) ⇒ Object
- #tf_env ⇒ Object
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
#config ⇒ Object (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_env ⇒ Object (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_env ⇒ Object
16 17 18 |
# File 'lib/yle_tf/tf_hook/runner.rb', line 16 def tf_env @tf_env ||= config.tf_env end |