Class: YleTf::Action::TfHooks

Inherits:
Object
  • Object
show all
Defined in:
lib/yle_tf/action/tf_hooks.rb

Defined Under Namespace

Classes: NoRunner

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ TfHooks

Returns a new instance of TfHooks.



9
10
11
# File 'lib/yle_tf/action/tf_hooks.rb', line 9

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/yle_tf/action/tf_hooks.rb', line 13

def call(env)
  @env = env

  hook_runner.run('pre')
  @app.call(env)
  hook_runner.run('post')
end

#configObject



37
38
39
# File 'lib/yle_tf/action/tf_hooks.rb', line 37

def config
  @env[:config]
end

#hook_envObject



29
30
31
32
33
34
35
# File 'lib/yle_tf/action/tf_hooks.rb', line 29

def hook_env
  {
    'TF_COMMAND'    => @env[:tf_command],
    'TF_ENV'        => @env[:tf_env],
    'TF_MODULE_DIR' => config.module_dir.to_s,
  }
end

#hook_runnerObject



21
22
23
24
25
26
27
# File 'lib/yle_tf/action/tf_hooks.rb', line 21

def hook_runner
  if run_hooks?
    TfHook::Runner.new(config, hook_env)
  else
    NoRunner
  end
end

#run_hooks?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/yle_tf/action/tf_hooks.rb', line 41

def run_hooks?
  !@env[:tf_options][:no_hooks]
end