Class: Juicer::Merger::Base
- Inherits:
-
Object
- Object
- Juicer::Merger::Base
- Includes:
- Chainable
- Defined in:
- lib/juicer/merger/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#dependency_resolver ⇒ Object
Returns the value of attribute dependency_resolver.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Instance Method Summary collapse
-
#append(file) ⇒ Object
(also: #<<)
Append contents to output.
-
#initialize(files = [], options = {}) ⇒ Base
constructor
A new instance of Base.
-
#save(file_or_stream) ⇒ Object
Save the merged contents.
Methods included from Chainable
included, #next_in_chain, #next_in_chain=
Constructor Details
#initialize(files = [], options = {}) ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 16 17 |
# File 'lib/juicer/merger/base.rb', line 11 def initialize(files = [], = {}) @files = [] @root = nil @options = @dependency_resolver ||= nil self.append files end |
Instance Attribute Details
#dependency_resolver ⇒ Object
Returns the value of attribute dependency_resolver.
8 9 10 |
# File 'lib/juicer/merger/base.rb', line 8 def dependency_resolver @dependency_resolver end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
9 10 11 |
# File 'lib/juicer/merger/base.rb', line 9 def files @files end |
Instance Method Details
#append(file) ⇒ Object Also known as: <<
Append contents to output. Resolves dependencies and adds required files recursively file = A file to add to merged content
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/juicer/merger/base.rb', line 24 def append(file) return file.each { |f| self << f } if file.class == Array return if @files.include?(file) if !@dependency_resolver.nil? path = File.(file) resolve_dependencies(path) elsif !@files.include?(file) @files << file end end |
#save(file_or_stream) ⇒ Object
Save the merged contents. If a filename is given the new file is written. If a stream is provided, contents are written to it.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/juicer/merger/base.rb', line 42 def save(file_or_stream) output = file_or_stream if output.is_a? String @root = Pathname.new(File.dirname(File.(output))) output = File.open(output, 'w') else @root = Pathname.new(File.(".")) end @files.each do |f| output.puts(merge(f)) end output.close if file_or_stream.is_a? String end |