Class: Kitchen::LifecycleHook::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/lifecycle_hook/base.rb

Overview

Base class for a lifecycle hook implementation.

A hook is bound to a single phase (for example pre_create) and decides, via #should_run?, whether it applies to the instance's platform before #run carries out the command.

Direct Known Subclasses

Local, Remote

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lifecycle_hooks, phase, hook) ⇒ Base

Returns a new instance of Base.

Parameters:



25
26
27
28
29
# File 'lib/kitchen/lifecycle_hook/base.rb', line 25

def initialize(lifecycle_hooks, phase, hook)
  @lifecycle_hooks = lifecycle_hooks
  @phase = phase
  @hook = hook
end

Instance Attribute Details

#hookHash (readonly)

Returns the raw hook configuration.

Returns:

  • (Hash)

    the raw hook configuration



20
21
22
# File 'lib/kitchen/lifecycle_hook/base.rb', line 20

def hook
  @hook
end

#lifecycle_hooksKitchen::LifecycleHooks (readonly)



14
15
16
# File 'lib/kitchen/lifecycle_hook/base.rb', line 14

def lifecycle_hooks
  @lifecycle_hooks
end

#phaseString (readonly)

Returns the lifecycle phase this hook is bound to.

Returns:

  • (String)

    the lifecycle phase this hook is bound to



17
18
19
# File 'lib/kitchen/lifecycle_hook/base.rb', line 17

def phase
  @phase
end

Instance Method Details

#loggerLogger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the lifecycle hook's logger otherwise.

Returns:

  • (Logger)

    the lifecycle hook's logger otherwise



53
54
55
# File 'lib/kitchen/lifecycle_hook/base.rb', line 53

def logger
  lifecycle_hooks.send(:logger)
end

#runvoid

This method returns an undefined value.

Carries out the hook's command. Subclasses must implement this.

Raises:

  • (NotImplementedError)

    unless overridden by a subclass



35
36
37
# File 'lib/kitchen/lifecycle_hook/base.rb', line 35

def run
  raise NotImplementedError
end

#should_run?TrueClass, FalseClass

Returns:

  • (TrueClass, FalseClass)


40
41
42
43
44
45
46
47
48
# File 'lib/kitchen/lifecycle_hook/base.rb', line 40

def should_run?
  if !includes.empty?
    includes.include?(platform_name)
  elsif !excludes.empty?
    !excludes.include?(platform_name)
  else
    true
  end
end