Module: Flok::UserHooksToManifestOrchestrator

Defined in:
lib/flok/hooks_compiler.rb

Overview

This converts all the user hooks into a manifest

Defined Under Namespace

Classes: UserHooksDSL

Class Method Summary collapse

Class Method Details

.convert_hooks_to_manifest(hooks_rb) ⇒ Object

Converts the ‘./config/hooks.rb` of the user into a HooksManifestEntry



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/flok/hooks_compiler.rb', line 118

def self.convert_hooks_to_manifest hooks_rb
  #Create a new manifest, this will be passed to each generator instance
  #along with a set of parameters. Each generator will update the 
  #hooks manifest
  manifest = HooksManifest.new

  #Evaluate the user hooks DSL which will create a listing of all the
  #user's requests in the accessible :hooks_requests member of the dsl environment
  hooks_dsl_env = UserHooksDSL.new
  hooks_dsl_env.instance_eval hooks_rb

  #For each user request, lookup the appropriate generator handler and then
  #call the generator
  hook_requests = hooks_dsl_env.hook_requests
  hook_requests.each do |gen_name, requests|
    generator = $generators[gen_name]
    raise "A hook request requested the generator by the name #{gen_name.inspect} but this was not a generator..." unless generator

    requests.each do |r|
      generator.call(manifest, r)
    end
  end

  return manifest
end

.register_hook_gen(name, &gen_block) ⇒ Object

Register a user hook generator to be available to the user in their ‘./config/hooks.rb` The name is what is used to find the correct generator when a user uses the hook :name DSL syntax



113
114
115
# File 'lib/flok/hooks_compiler.rb', line 113

def self.register_hook_gen name, &gen_block
  $generators[name] = gen_block
end