Class: Kitchen::LifecycleHook::Base
- Inherits:
-
Object
- Object
- Kitchen::LifecycleHook::Base
- 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.
Instance Attribute Summary collapse
-
#hook ⇒ Hash
readonly
The raw hook configuration.
- #lifecycle_hooks ⇒ Kitchen::LifecycleHooks readonly
-
#phase ⇒ String
readonly
The lifecycle phase this hook is bound to.
Instance Method Summary collapse
-
#initialize(lifecycle_hooks, phase, hook) ⇒ Base
constructor
A new instance of Base.
-
#logger ⇒ Logger
private
The lifecycle hook's logger otherwise.
-
#run ⇒ void
Carries out the hook's command.
- #should_run? ⇒ TrueClass, FalseClass
Constructor Details
#initialize(lifecycle_hooks, phase, hook) ⇒ Base
Returns a new instance of Base.
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
#hook ⇒ Hash (readonly)
Returns the raw hook configuration.
20 21 22 |
# File 'lib/kitchen/lifecycle_hook/base.rb', line 20 def hook @hook end |
#lifecycle_hooks ⇒ Kitchen::LifecycleHooks (readonly)
14 15 16 |
# File 'lib/kitchen/lifecycle_hook/base.rb', line 14 def lifecycle_hooks @lifecycle_hooks end |
#phase ⇒ String (readonly)
Returns 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
#logger ⇒ Logger
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.
53 54 55 |
# File 'lib/kitchen/lifecycle_hook/base.rb', line 53 def logger lifecycle_hooks.send(:logger) end |
#run ⇒ void
This method returns an undefined value.
Carries out the hook's command. Subclasses must implement this.
35 36 37 |
# File 'lib/kitchen/lifecycle_hook/base.rb', line 35 def run raise NotImplementedError end |
#should_run? ⇒ 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 |