Class: Backend
Overview
Base class from which to subclass other backends. Subclasses must implement the run method that gets passed a file name and must (0) set the @layers instance var to a hash of layers containing the metadata gathered and call the write_layers method when finished to save that data.
Direct Known Subclasses
Class Method Summary collapse
- .run(file) ⇒ Object
-
.with_no_output ⇒ Object
Suppress STDOUT while a block runs.
-
.write_layers ⇒ Object
Output the @layers hash as JSON where augment expects it.
Class Method Details
.run(file) ⇒ Object
12 13 14 |
# File 'lib/backends/backend.rb', line 12 def run(file) raise "Base Backend class shouldn't be used for real augmentation." end |
.with_no_output ⇒ Object
Suppress STDOUT while a block runs.
27 28 29 30 31 32 |
# File 'lib/backends/backend.rb', line 27 def with_no_output old_stdout = $stdout.clone $stdout.reopen(File.new('/dev/null','w')) yield $stdout.reopen(old_stdout) end |
.write_layers ⇒ Object
Output the @layers hash as JSON where augment expects it.
17 18 19 20 21 22 23 24 |
# File 'lib/backends/backend.rb', line 17 def write_layers @layers.each do |file, layers| FileUtils.mkpath(File.dirname(file) + '/.augment') File.open(Augment.augment_path(file), 'w') do |f| f.puts "[#{layers.map{ |l| l.to_json }.join(", \n")}]" end end end |