Class: Flok::HooksManifest
- Inherits:
-
Object
- Object
- Flok::HooksManifest
- 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
-
#<<(entry) ⇒ Object
Accepts a HooksManifestEntry which can match a line and then return some text that should be apart of that line.
-
#initialize ⇒ HooksManifest
constructor
A new instance of HooksManifest.
-
#transform_line(line) ⇒ Object
Returns a copy of the line with transformations if needed.
Constructor Details
#initialize ⇒ HooksManifest
Returns a new instance of HooksManifest.
25 26 27 |
# File 'lib/flok/hooks_compiler.rb', line 25 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
51 52 53 |
# File 'lib/flok/hooks_compiler.rb', line 51 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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/flok/hooks_compiler.rb', line 33 def transform_line line puts "a3" #Get all the matched HooksManifestEntry(s) injected_code = @manifest_entries.select{|e| e.does_match? line}.map{|e| e.code_for_line(line)} puts "an" #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 puts "a4" #Else, nothing was found, keep moving along and don't transform the line return line end |