Class: Kafo::Hooking
- Inherits:
-
Object
- Object
- Kafo::Hooking
- Defined in:
- lib/kafo/hooking.rb
Constant Summary collapse
- TYPES =
pre_migrations - just after kafo reads its configuration - useful for config file updates. Only in this stage it is posible to request config reload (‘Kafo.request_config_reload`) to get in our changes 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_commit - after validations or interactive wizard have completed, all parameter values are set but not yet stored in the answer file pre - just before puppet is executed to converge system post - just after puppet is executed to converge system
[:pre_migrations, :boot, :init, :pre, :post, :pre_values, :pre_validations, :pre_commit]
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_commit(name, &block) ⇒ Object
- #register_pre_migrations(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.
17 18 19 20 |
# File 'lib/kafo/hooking.rb', line 17 def initialize self.hooks = Hash.new { |h, k| h[k] = {} } @loaded = false end |
Instance Attribute Details
#hooks ⇒ Object
Returns the value of attribute hooks.
15 16 17 |
# File 'lib/kafo/hooking.rb', line 15 def hooks @hooks end |
#kafo ⇒ Object
Returns the value of attribute kafo.
15 16 17 |
# File 'lib/kafo/hooking.rb', line 15 def kafo @kafo end |
Instance Method Details
#execute(group) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/kafo/hooking.rb', line 47 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
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/kafo/hooking.rb', line 26 def load base_dirs = [File.join([KafoConfigure.root_dir, 'hooks']), KafoConfigure.config.app[:hook_dirs]].flatten 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
43 44 45 |
# File 'lib/kafo/hooking.rb', line 43 def loaded? @loaded end |
#logger ⇒ Object
22 23 24 |
# File 'lib/kafo/hooking.rb', line 22 def logger KafoConfigure.logger end |
#register_boot(name, &block) ⇒ Object
61 62 63 |
# File 'lib/kafo/hooking.rb', line 61 def register_boot(name, &block) register(:boot, name, &block) end |
#register_init(name, &block) ⇒ Object
65 66 67 |
# File 'lib/kafo/hooking.rb', line 65 def register_init(name, &block) register(:init, name, &block) end |
#register_post(name, &block) ⇒ Object
85 86 87 |
# File 'lib/kafo/hooking.rb', line 85 def register_post(name, &block) register(:post, name, &block) end |
#register_pre(name, &block) ⇒ Object
81 82 83 |
# File 'lib/kafo/hooking.rb', line 81 def register_pre(name, &block) register(:pre, name, &block) end |
#register_pre_commit(name, &block) ⇒ Object
77 78 79 |
# File 'lib/kafo/hooking.rb', line 77 def register_pre_commit(name, &block) register(:pre_commit, name, &block) end |
#register_pre_migrations(name, &block) ⇒ Object
57 58 59 |
# File 'lib/kafo/hooking.rb', line 57 def register_pre_migrations(name, &block) register(:pre_migrations, name, &block) end |
#register_pre_validations(name, &block) ⇒ Object
73 74 75 |
# File 'lib/kafo/hooking.rb', line 73 def register_pre_validations(name, &block) register(:pre_validations, name, &block) end |
#register_pre_values(name, &block) ⇒ Object
69 70 71 |
# File 'lib/kafo/hooking.rb', line 69 def register_pre_values(name, &block) register(:pre_values, name, &block) end |