Class: Kitchen::LifecycleHooks

Inherits:
Object
  • Object
show all
Includes:
Configurable, Logging
Defined in:
lib/kitchen/lifecycle_hooks.rb

Overview

A helper object used by Instance to coordinate lifecycle hook calls from the ‘lifecycle:` configuration section.

Since:

  • 1.22

Instance Attribute Summary collapse

Attributes included from Configurable

#instance

Instance Method Summary collapse

Methods included from Logging

#banner, #debug, #error, #fatal, #info, #warn

Methods included from Configurable

#[], #bourne_shell?, #calculate_path, #config_keys, #diagnose, #diagnose_plugin, #finalize_config!, included, #name, #powershell_shell?, #remote_path_join, #unix_os?, #verify_dependencies, #windows_os?

Constructor Details

#initialize(config, state_file) ⇒ LifecycleHooks

Returns a new instance of LifecycleHooks.

Since:

  • 1.22



34
35
36
37
# File 'lib/kitchen/lifecycle_hooks.rb', line 34

def initialize(config, state_file)
  init_config(config)
  @state_file = state_file
end

Instance Attribute Details

#state_fileKitchen::StateFile (readonly)

Returns:

Since:

  • 1.22



52
53
54
# File 'lib/kitchen/lifecycle_hooks.rb', line 52

def state_file
  @state_file
end

Instance Method Details

#run_with_hooks(phase, state_file, &block) ⇒ void

This method returns an undefined value.

Run a lifecycle phase with the pre and post hooks.

Parameters:

  • phase (String)

    Lifecycle phase which is being executed.

  • state_file (StateFile)

    Instance state file object.

  • block (Proc)

    Block of code implementing the lifecycle phase.

Since:

  • 1.22



45
46
47
48
49
# File 'lib/kitchen/lifecycle_hooks.rb', line 45

def run_with_hooks(phase, state_file, &block)
  run(phase, :pre)
  yield
  run(phase, :post)
end