Class: Gasoline::Patchor
- Inherits:
-
Object
- Object
- Gasoline::Patchor
- Defined in:
- lib/gasoline/patchor.rb
Overview
The Patchor will do all the patching on the Propane support file, it finds (and creates if needed) the file, adds the Propane header, and then adds all the drops from the jerrycan.
Constant Summary collapse
- PATCHOR_FILE =
"#{ENV['HOME']}/Library/Application Support/Propane/unsupported/caveatPatchor.js"
Instance Method Summary collapse
-
#bootstrap ⇒ Object
Will create the Propane, caveatPatchor.js file.
-
#cut_line_index ⇒ Object
The index of the line matching the cut snippet, if it can’t be found we’ll take the last line.
-
#drops ⇒ Object
The contents of our Jerrycan, laid bare to be patched.
-
#initialize ⇒ Patchor
constructor
A new instance of Patchor.
-
#jerrycan ⇒ Object
An instance of the Jerrycan, mainly added to have quick access to it, while developing.
-
#lines ⇒ Object
Current lines in memory.
-
#load_lines ⇒ Object
Loads the entire file into memory.
-
#patch_it_chewie ⇒ Object
Transform the @lines to have:.
-
#patch_it_chewie! ⇒ Object
First fills up the @lines instance, then saves the file.
- #patchor_file ⇒ Object
-
#save ⇒ Object
Writes the file to disk.
Constructor Details
#initialize ⇒ Patchor
Returns a new instance of Patchor.
8 9 10 11 12 |
# File 'lib/gasoline/patchor.rb', line 8 def initialize @lines = [] bootstrap load_lines end |
Instance Method Details
#bootstrap ⇒ Object
Will create the Propane, caveatPatchor.js file
19 20 21 22 23 24 25 26 27 |
# File 'lib/gasoline/patchor.rb', line 19 def bootstrap return if File.exist?(patchor_file) FileUtils.mkdir_p(File.split(patchor_file).first) FileUtils.touch(patchor_file) File.open(patchor_file, "w") do |f| f.write(Gasoline::Texts::propane_header) end end |
#cut_line_index ⇒ Object
The index of the line matching the cut snippet, if it can’t be found we’ll take the last line.
Returns an int
45 46 47 |
# File 'lib/gasoline/patchor.rb', line 45 def cut_line_index @lines.find_index{|line| line =~ /#{Gasoline::Texts::cut_here_line}/} || @lines.length end |
#drops ⇒ Object
The contents of our Jerrycan, laid bare to be patched.
Returns an array of ‘Drop`s
60 61 62 |
# File 'lib/gasoline/patchor.rb', line 60 def drops jerrycan.drops end |
#jerrycan ⇒ Object
An instance of the Jerrycan, mainly added to have quick access to it, while developing.
Returns a ‘Jerrycan` instance
53 54 55 |
# File 'lib/gasoline/patchor.rb', line 53 def jerrycan @jerrycan ||= Gasoline::Jerrycan.new end |
#lines ⇒ Object
Current lines in memory
Returns an array of lines
32 33 34 |
# File 'lib/gasoline/patchor.rb', line 32 def lines @lines end |
#load_lines ⇒ Object
Loads the entire file into memory
37 38 39 |
# File 'lib/gasoline/patchor.rb', line 37 def load_lines @lines = File.readlines(patchor_file) end |
#patch_it_chewie ⇒ Object
Transform the @lines to have:
1. All the lines above the cut
2. The cut here snippet
3. All patches from the drops. (will download them)
Returns an array of lines
71 72 73 74 75 76 |
# File 'lib/gasoline/patchor.rb', line 71 def patch_it_chewie to_keep = @lines[0...cut_line_index] snippet = [Gasoline::Texts::cut_here_snippet] to_add = drops.collect(&:patch).compact @lines = (to_keep + snippet + to_add) end |
#patch_it_chewie! ⇒ Object
First fills up the @lines instance, then saves the file
79 80 81 82 83 |
# File 'lib/gasoline/patchor.rb', line 79 def patch_it_chewie! patch_it_chewie Gasoline::Applescript.refresh_propane_if_running save end |
#patchor_file ⇒ Object
14 15 16 |
# File 'lib/gasoline/patchor.rb', line 14 def patchor_file PATCHOR_FILE end |
#save ⇒ Object
Writes the file to disk.
86 87 88 89 |
# File 'lib/gasoline/patchor.rb', line 86 def save File.open("file.tmp", "w") {|f| f.write(@lines.join(""))} FileUtils.mv("file.tmp", patchor_file) end |