Class: Torba::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/torba/manifest.rb

Overview

Represents Torbafile.

Since:

  • 0.1.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManifest

Returns a new instance of Manifest.

Since:

  • 0.1.0



40
41
42
# File 'lib/torba/manifest.rb', line 40

def initialize
  @packages = []
end

Instance Attribute Details

#packagesObject (readonly)

all packages defined in Torbafile

Since:

  • 0.1.0



21
22
23
# File 'lib/torba/manifest.rb', line 21

def packages
  @packages
end

Class Method Details

.self.build(file_path) ⇒ Manifest .self.buildManifest

Reads Torbafile and evaluates it.

Overloads:

  • .self.build(file_path) ⇒ Manifest

    Parameters:

    • file_path (String)

      absolute path to Torbafile

  • .self.buildManifest

    Reads Torbafile from current directory

Returns:

Since:

  • 0.1.0



31
32
33
34
35
36
37
38
# File 'lib/torba/manifest.rb', line 31

def self.build(file_path = nil)
  file_path ||= File.join(Dir.pwd, "Torbafile")

  manifest = new
  content = File.read(file_path)
  manifest.instance_eval(content, file_path)
  manifest
end

Instance Method Details

#gh_release(name = nil, options = {}) ⇒ Object

Since:

  • 0.1.0



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/torba/manifest.rb', line 52

def gh_release(name = nil, options = {})
  if name.is_a?(Hash)
    options, name = name, nil
  end

  source = options.fetch(:source)
  tag = options.fetch(:tag)
  remote_source = RemoteSources::GithubRelease.new(source, tag)

  name ||= remote_source.repository_name
  packages << Package.new(name, remote_source, options)
end

#load_pathArray<String>

Returns list of paths to each prepared asset package. It should be appended to the Sprockets’ load_path.

Returns:

  • (Array<String>)

    list of paths to each prepared asset package. It should be appended to the Sprockets’ load_path.

Since:

  • 0.1.0



96
97
98
# File 'lib/torba/manifest.rb', line 96

def load_path
  packages.map(&:load_path)
end

#non_js_css_logical_pathsArray<String>

Note:

Avoid importing everything from a package as it’ll be precompiled and accessible publicly.

Returns logical paths that packages contain except JS ans CSS. It should be appended to the Sprockets’ precompile list. Packages’ JS and CSS are meant to be included into application.js/.css and not to be compiled alone (you can add them by hand though).

Returns:

  • (Array<String>)

    logical paths that packages contain except JS ans CSS. It should be appended to the Sprockets’ precompile list. Packages’ JS and CSS are meant to be included into application.js/.css and not to be compiled alone (you can add them by hand though).

See Also:

Since:

  • 0.3.0



109
110
111
# File 'lib/torba/manifest.rb', line 109

def non_js_css_logical_paths
  packages.flat_map(&:non_js_css_logical_paths)
end

#npm(name = nil, options = {}) ⇒ Object

Since:

  • 0.3.0



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/torba/manifest.rb', line 75

def npm(name = nil, options = {})
  if name.is_a?(Hash)
    options, name = name, nil
  end

  package_name = options.fetch(:package)
  version = options.fetch(:version)
  remote_source = RemoteSources::Npm.new(package_name, version)

  name ||= remote_source.package
  packages << Package.new(name, remote_source, options)
end

#packvoid

This method returns an undefined value.

Builds all #packages

Since:

  • 0.1.0



90
91
92
# File 'lib/torba/manifest.rb', line 90

def pack
  packages.each(&:build)
end

#targz(name, options = {}) ⇒ Object

Since:

  • 0.3.0



67
68
69
70
71
# File 'lib/torba/manifest.rb', line 67

def targz(name, options = {})
  url = options.fetch(:url)
  remote_source = RemoteSources::Targz.new(url)
  packages << Package.new(name, remote_source, options)
end

#verifyvoid

This method returns an undefined value.

Verifies all #packages

Raises:

Since:

  • 0.1.0



116
117
118
119
120
121
122
# File 'lib/torba/manifest.rb', line 116

def verify
  missing = packages.reject(&:verify)

  if missing.any?
    raise Errors::MissingPackages.new(missing)
  end
end

#zip(name, options = {}) ⇒ Object

Since:

  • 0.1.0



45
46
47
48
49
# File 'lib/torba/manifest.rb', line 45

def zip(name, options = {})
  url = options.fetch(:url)
  remote_source = RemoteSources::Zip.new(url)
  packages << Package.new(name, remote_source, options)
end