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.
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
#config ⇒ Object (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_env ⇒ Object (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_env ⇒ Object
14 15 16 |
# File 'lib/yle_tf/tf_hook/runner.rb', line 14 def tf_env @tf_env ||= config.tf_env end |