Class: Jsus::Packager

Inherits:
Object
  • Object
show all
Defined in:
lib/jsus/packager.rb

Overview

Packager is a plain simple class accepting several source files and joining their contents.

It uses Container for storage which means it automatically sorts sources.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sources) ⇒ Packager

Inits packager with the given sources.

Parameters:

  • sources (Container, Array)

    source files



17
18
19
20
21
22
23
24
# File 'lib/jsus/packager.rb', line 17

def initialize(sources)
  @sources = case sources
  when Array
    Container.new(*sources)
  else
    sources
  end
end

Instance Attribute Details

#containerObject

Container with source files



10
11
12
# File 'lib/jsus/packager.rb', line 10

def container
  @container
end

Instance Method Details

#pack(output_file = nil) ⇒ String

Concatenates all the sources' contents into a single string. If given a filename, outputs into a file.

Parameters:

  • output_file (String, nil) (defaults to: nil)

    output file name

Returns:

  • (String)

    concatenated source files



38
39
40
41
42
43
44
45
46
# File 'lib/jsus/packager.rb', line 38

def pack(output_file = nil)
  result = sources.map {|s| s.source }.join("\n")
  if output_file
    FileUtils.mkdir_p(File.dirname(output_file))
    File.open(output_file, "w") {|f| f << result }
  end

  result
end

#sourcesJsus::Container

Returns container with source files.

Returns:



28
29
30
# File 'lib/jsus/packager.rb', line 28

def sources
  @sources
end