Class: Flok::UserHooksToManifestOrchestrator::UserHooksDSL
- Inherits:
-
Object
- Object
- Flok::UserHooksToManifestOrchestrator::UserHooksDSL
- Defined in:
- lib/flok/hooks_compiler.rb
Overview
Interpret ‘./config/hooks.rb` to call the associated registered hook gen block
Instance Attribute Summary collapse
-
#hook_requests ⇒ Object
Returns the value of attribute hook_requests.
Instance Method Summary collapse
-
#hook(names, &block) ⇒ Object
Install a hook.
-
#initialize ⇒ UserHooksDSL
constructor
A new instance of UserHooksDSL.
Constructor Details
#initialize ⇒ UserHooksDSL
Returns a new instance of UserHooksDSL.
147 148 149 150 151 |
# File 'lib/flok/hooks_compiler.rb', line 147 def initialize #Each user hook call adds a request to this hash #which is then processed by each matching hook generator @hook_requests = {} end |
Instance Attribute Details
#hook_requests ⇒ Object
Returns the value of attribute hook_requests.
146 147 148 |
# File 'lib/flok/hooks_compiler.rb', line 146 def hook_requests @hook_requests end |
Instance Method Details
#hook(names, &block) ⇒ Object
Install a hook. Leads to eventually calling the relavent hook generator. The anmes argument takes one key-value pair e.g. => :settings_changed, this would mean the hook generator named ‘goto’ and it should create a hook event called ‘settings_changed’. The block is then passed on to each hook generator. See the docs on hooks.md for information on what each block function takes
158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/flok/hooks_compiler.rb', line 158 def hook names, &block #The names parameter key = names.keys.first hook_event_name = names.values.first raise "You didn't supply a hook generator name or the event name... Got #{key.inspect} and #{hook_event_name.inspect}. e.g. hook :goto => :changed, {...}" unless key and hook_event_name @hook_requests[key] ||= [] @hook_requests[key] << { :hook_event_name => hook_event_name, :block => block } end |