Class: Flok::HooksManifest

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

Overview

A hooks manifest contains all the information needed so that the hooks compiler can find can change the code

Instance Method Summary collapse

Constructor Details

#initializeHooksManifest

Returns a new instance of HooksManifest.



22
23
24
# File 'lib/flok/hooks_compiler.rb', line 22

def initialize
  @manifest_entries = []
end

Instance Method Details

#<<(entry) ⇒ Object

Accepts a HooksManifestEntry which can match a line and then return some text that should be apart of that line. Multiple matching manifest entries is possible



45
46
47
# File 'lib/flok/hooks_compiler.rb', line 45

def <<(entry)
  @manifest_entries << entry
end

#transform_line(line) ⇒ Object

Returns a copy of the line with transformations if needed. For example, if a line contains a hook entry point, like HOOK_ENTRY and the manifest contains code that should be inserted there, this will return the inserted code (which may then be multiple lines) And will also remove the comment itself



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/flok/hooks_compiler.rb', line 30

def transform_line line
  #Get all the matched HooksManifestEntry(s) 
  injected_code = @manifest_entries.select{|e| e.does_match? line}.map{|e| e.code_for_line(line)}

  #If there is a match of at least one hook, remove the original line and replace it
  #with all the newly found code from the HooksManifestEntry(s)
  return injected_code.join("\n") if injected_code.count > 0

  #Else, nothing was found, keep moving along and don't transform the line
  return line
end