Class: Flok::UserHooksToManifestOrchestrator::UserHooksDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/flok/hooks_compiler.rb

Overview

Interpret ‘./config/hooks.rb` to call the associated registered hook gen block

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUserHooksDSL

Returns a new instance of UserHooksDSL.



141
142
143
144
145
# File 'lib/flok/hooks_compiler.rb', line 141

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_requestsObject

Returns the value of attribute hook_requests.



140
141
142
# File 'lib/flok/hooks_compiler.rb', line 140

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



152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/flok/hooks_compiler.rb', line 152

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