Class: Torba::Manifest
- Inherits:
-
Object
- Object
- Torba::Manifest
- Defined in:
- lib/torba/manifest.rb
Overview
Represents Torbafile.
Instance Attribute Summary collapse
-
#packages ⇒ Object
readonly
all packages defined in Torbafile.
Class Method Summary collapse
-
.build(file_path = ENV["TORBA_FILE"]) ⇒ Manifest
Reads Torbafile and evaluates it.
Instance Method Summary collapse
-
#find_packages_by_name(name) ⇒ Array<Package>
Where each package name at least partially matches given name.
-
#gh_release(name = nil, options = {}) ⇒ Object
Adds Package with RemoteSources::GithubRelease to #packages.
-
#initialize ⇒ Manifest
constructor
A new instance of Manifest.
-
#load_path ⇒ Array<String>
List of paths to each prepared asset package.
-
#non_js_css_logical_paths ⇒ Array<String>
Logical paths that packages contain except JS ans CSS.
-
#npm(name = nil, options = {}) ⇒ Object
Adds Package with RemoteSources::Npm to #packages.
-
#pack ⇒ void
Builds all #packages.
-
#targz(name, options = {}) ⇒ Object
Adds Package with RemoteSources::Targz to #packages.
-
#verify ⇒ void
Verifies all #packages.
-
#zip(name, options = {}) ⇒ Object
Adds Package with RemoteSources::Zip to #packages.
Constructor Details
#initialize ⇒ Manifest
Returns a new instance of Manifest.
41 42 43 |
# File 'lib/torba/manifest.rb', line 41 def initialize @packages = [] end |
Instance Attribute Details
#packages ⇒ Object (readonly)
all packages defined in Torbafile
22 23 24 |
# File 'lib/torba/manifest.rb', line 22 def packages @packages end |
Class Method Details
.self.build(file_path) ⇒ Manifest .self.build ⇒ Manifest
Reads Torbafile and evaluates it.
32 33 34 35 36 37 38 39 |
# 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 |
Instance Method Details
#find_packages_by_name(name) ⇒ Array<Package>
Returns where each package name at least partially matches given name.
127 128 129 130 131 132 |
# 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 = {}) ⇒ Object
Adds Package with RemoteSources::GithubRelease to #packages
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/torba/manifest.rb', line 53 def gh_release(name = nil, = {}) if name.is_a?(Hash) , name = name, nil end source = .fetch(:source) tag = .fetch(:tag) remote_source = RemoteSources::GithubRelease.new(source, tag) name ||= remote_source.repository_name packages << Package.new(name, remote_source, ) end |
#load_path ⇒ Array<String>
Returns list of paths to each prepared asset package. It should be appended to the Sprockets’ load_path.
97 98 99 |
# File 'lib/torba/manifest.rb', line 97 def load_path packages.map(&:load_path) end |
#non_js_css_logical_paths ⇒ Array<String>
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).
110 111 112 |
# 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 = {}) ⇒ Object
Adds Package with RemoteSources::Npm to #packages
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/torba/manifest.rb', line 76 def npm(name = nil, = {}) if name.is_a?(Hash) , name = name, nil end package_name = .fetch(:package) version = .fetch(:version) remote_source = RemoteSources::Npm.new(package_name, version) name ||= remote_source.package packages << Package.new(name, remote_source, ) end |
#pack ⇒ void
This method returns an undefined value.
Builds all #packages
91 92 93 |
# File 'lib/torba/manifest.rb', line 91 def pack packages.each(&:build) end |
#targz(name, options = {}) ⇒ Object
Adds Package with RemoteSources::Targz to #packages
68 69 70 71 72 |
# File 'lib/torba/manifest.rb', line 68 def targz(name, = {}) url = .fetch(:url) remote_source = RemoteSources::Targz.new(url) packages << Package.new(name, remote_source, ) end |
#verify ⇒ void
This method returns an undefined value.
Verifies all #packages
117 118 119 120 121 122 123 |
# 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 = {}) ⇒ Object
Adds Package with RemoteSources::Zip to #packages
46 47 48 49 50 |
# File 'lib/torba/manifest.rb', line 46 def zip(name, = {}) url = .fetch(:url) remote_source = RemoteSources::Zip.new(url) packages << Package.new(name, remote_source, ) end |