class Torba::Manifest

Represents Torbafile.

Attributes

packages[R]

all packages defined in Torbafile

Public Class Methods

build(file_path = ENV["TORBA_FILE"]) click to toggle source

Reads Torbafile and evaluates it. @return [Manifest]

@overload self.build(file_path)

@param file_path [String] absolute path to Torbafile

@overload self.build

Reads Torbafile from current directory
# File lib/torba/manifest.rb, line 32
def self.build(file_path = ENV["TORBA_FILE"])
  file_path ||= File.join(Dir.pwd, "Torbafile")

  manifest = new
  content = File.read(file_path)
  manifest.instance_eval(content, file_path)
  manifest
end
new() click to toggle source
# File lib/torba/manifest.rb, line 41
def initialize
  @packages = []
end

Public Instance Methods

find_packages_by_name(name) click to toggle source

@return [Array<Package>] where each package name at least partially matches given name. @since 0.7.0

# File lib/torba/manifest.rb, line 127
def find_packages_by_name(name)
  re = Regexp.new(name, Regexp::IGNORECASE)
  packages.find_all do |package|
    package.name =~ re
  end
end
gh_release(name = nil, options = {}) click to toggle source

Adds {Package} with {RemoteSources::GithubRelease} to {#packages}

# File lib/torba/manifest.rb, line 53
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_path() click to toggle source

@return [Array<String>] list of paths to each prepared asset package.

It should be appended to the Sprockets' load_path.
# File lib/torba/manifest.rb, line 97
def load_path
  packages.map(&:load_path)
end
non_js_css_logical_paths() click to toggle source

@return [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).

@note Avoid importing everything from a package as it'll be precompiled and accessible

publicly.

@see Package#import_paths @see Package#non_js_css_logical_paths @since 0.3.0

# File lib/torba/manifest.rb, line 110
def non_js_css_logical_paths
  packages.flat_map(&:non_js_css_logical_paths)
end
npm(name = nil, options = {}) click to toggle source

Adds {Package} with {RemoteSources::Npm} to {#packages} @since 0.3.0

# File lib/torba/manifest.rb, line 76
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
pack() click to toggle source

Builds all {#packages} @return [void]

# File lib/torba/manifest.rb, line 91
def pack
  packages.each(&:build)
end
targz(name, options = {}) click to toggle source

Adds {Package} with {RemoteSources::Targz} to {#packages} @since 0.3.0

# File lib/torba/manifest.rb, line 68
def targz(name, options = {})
  url = options.fetch(:url)
  remote_source = RemoteSources::Targz.new(url)
  packages << Package.new(name, remote_source, options)
end
verify() click to toggle source

Verifies all {#packages} @return [void] @raise [Errors::MissingPackages] if at least one package is not build.

# File lib/torba/manifest.rb, line 117
def verify
  missing = packages.reject(&:verify)

  if missing.any?
    raise Errors::MissingPackages.new(missing)
  end
end
zip(name, options = {}) click to toggle source

Adds {Package} with {RemoteSources::Zip} to {#packages}

# File lib/torba/manifest.rb, line 46
def zip(name, options = {})
  url = options.fetch(:url)
  remote_source = RemoteSources::Zip.new(url)
  packages << Package.new(name, remote_source, options)
end