Class: Kafo::Hooking
- Inherits:
-
Object
- Object
- Kafo::Hooking
- Defined in:
- lib/kafo/hooking.rb
Constant Summary collapse
- TYPES =
boot - before kafo is ready to work, useful for adding new app arguments, logger won’t work yet init - just after hooking is initialized and kafo is configured, parameters have no values yet pre_values - just before value from CLI is set to parameters (they already have default values) pre_validations - just after system checks and before validations are executed (and before interactive wizard is started), at this point all parameter values are already set but not yet stored in answer file pre - just before puppet is executed to converge system post - just after puppet is executed to converge system
[:boot, :init, :pre, :post, :pre_values, :pre_validations]
Instance Attribute Summary collapse
-
#hooks ⇒ Object
Returns the value of attribute hooks.
-
#kafo ⇒ Object
Returns the value of attribute kafo.
Instance Method Summary collapse
- #execute(group) ⇒ Object
-
#initialize ⇒ Hooking
constructor
A new instance of Hooking.
- #load ⇒ Object
- #loaded? ⇒ Boolean
- #logger ⇒ Object
- #register_boot(name, &block) ⇒ Object
- #register_init(name, &block) ⇒ Object
- #register_post(name, &block) ⇒ Object
- #register_pre(name, &block) ⇒ Object
- #register_pre_validations(name, &block) ⇒ Object
- #register_pre_values(name, &block) ⇒ Object
Constructor Details
#initialize ⇒ Hooking
Returns a new instance of Hooking.
15 16 17 18 |
# File 'lib/kafo/hooking.rb', line 15 def initialize self.hooks = Hash.new { |h, k| h[k] = {} } @loaded = false end |
Instance Attribute Details
#hooks ⇒ Object
Returns the value of attribute hooks.
13 14 15 |
# File 'lib/kafo/hooking.rb', line 13 def hooks @hooks end |
#kafo ⇒ Object
Returns the value of attribute kafo.
13 14 15 |
# File 'lib/kafo/hooking.rb', line 13 def kafo @kafo end |
Instance Method Details
#execute(group) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/kafo/hooking.rb', line 45 def execute(group) logger.info "Executing hooks in group #{group}" self.hooks[group].keys.sort_by(&:to_s).each do |name| hook = self.hooks[group][name] result = HookContext.execute(self.kafo, &hook) logger.debug "Hook #{name} returned #{result.inspect}" end logger.info "All hooks in group #{group} finished" end |
#load ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/kafo/hooking.rb', line 24 def load base_dirs = [File.join([KafoConfigure.root_dir, 'hooks']), KafoConfigure.config.app[:hook_dirs]] base_dirs.each do |base_dir| TYPES.each do |hook_type| dir = File.join(base_dir, hook_type.to_s) Dir.glob(dir + "/*.rb").sort.each do |file| logger.debug "Loading hook #{file}" hook = File.read(file) hook_block = proc { instance_eval(hook, file, 1) } register(hook_type, file, &hook_block) end end @loaded = true end self end |
#loaded? ⇒ Boolean
41 42 43 |
# File 'lib/kafo/hooking.rb', line 41 def loaded? @loaded end |
#logger ⇒ Object
20 21 22 |
# File 'lib/kafo/hooking.rb', line 20 def logger KafoConfigure.logger end |
#register_boot(name, &block) ⇒ Object
55 56 57 |
# File 'lib/kafo/hooking.rb', line 55 def register_boot(name, &block) register(:boot, name, &block) end |
#register_init(name, &block) ⇒ Object
59 60 61 |
# File 'lib/kafo/hooking.rb', line 59 def register_init(name, &block) register(:init, name, &block) end |
#register_post(name, &block) ⇒ Object
75 76 77 |
# File 'lib/kafo/hooking.rb', line 75 def register_post(name, &block) register(:post, name, &block) end |
#register_pre(name, &block) ⇒ Object
71 72 73 |
# File 'lib/kafo/hooking.rb', line 71 def register_pre(name, &block) register(:pre, name, &block) end |
#register_pre_validations(name, &block) ⇒ Object
67 68 69 |
# File 'lib/kafo/hooking.rb', line 67 def register_pre_validations(name, &block) register(:pre_validations, name, &block) end |
#register_pre_values(name, &block) ⇒ Object
63 64 65 |
# File 'lib/kafo/hooking.rb', line 63 def register_pre_values(name, &block) register(:pre_values, name, &block) end |