Class: Licensed::Source::Manifest
- Inherits:
-
Object
- Object
- Licensed::Source::Manifest
- Defined in:
- lib/licensed/source/manifest.rb
Instance Method Summary collapse
- #dependencies ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(config) ⇒ Manifest
constructor
A new instance of Manifest.
-
#manifest ⇒ Object
Returns parsed manifest data for the app.
-
#manifest_path ⇒ Object
Returns the manifest location for the app.
-
#package_version(sources) ⇒ Object
Returns the latest git SHA available from ‘sources`.
-
#packages ⇒ Object
Returns a map of package names -> array of full source paths found in the app manifest.
-
#sources_license_path(sources) ⇒ Object
Returns the top-most directory that is common to all paths in ‘sources`.
- #type ⇒ Object
Constructor Details
#initialize(config) ⇒ Manifest
Returns a new instance of Manifest.
7 8 9 |
# File 'lib/licensed/source/manifest.rb', line 7 def initialize(config) @config = config end |
Instance Method Details
#dependencies ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/licensed/source/manifest.rb', line 19 def dependencies @dependencies ||= packages.map do |package_name, sources| Dependency.new(sources_license_path(sources), { "type" => type, "name" => package_name, "version" => package_version(sources) }) end end |
#enabled? ⇒ Boolean
11 12 13 |
# File 'lib/licensed/source/manifest.rb', line 11 def enabled? @config.enabled?(type) && File.exist?(manifest_path) end |
#manifest ⇒ Object
Returns parsed manifest data for the app
62 63 64 65 66 67 68 69 |
# File 'lib/licensed/source/manifest.rb', line 62 def manifest case manifest_path.extname.downcase.delete "." when "json" JSON.parse(File.read(manifest_path)) when "yml", "yaml" YAML.load_file(manifest_path) end end |
#manifest_path ⇒ Object
Returns the manifest location for the app
72 73 74 75 76 77 |
# File 'lib/licensed/source/manifest.rb', line 72 def manifest_path path = @config["manifest"]["path"] if @config["manifest"] return Licensed::Git.repository_root.join(path) if path @config.cache_path.join("manifest.json") end |
#package_version(sources) ⇒ Object
Returns the latest git SHA available from ‘sources`
43 44 45 46 47 48 49 |
# File 'lib/licensed/source/manifest.rb', line 43 def package_version(sources) return if sources.nil? || sources.empty? sources.map { |s| Licensed::Git.version(s) } .compact .max_by { |sha| Licensed::Git.commit_date(sha) } end |
#packages ⇒ Object
Returns a map of package names -> array of full source paths found in the app manifest
53 54 55 56 57 58 59 |
# File 'lib/licensed/source/manifest.rb', line 53 def packages manifest.each_with_object({}) do |(src, package_name), hsh| next if src.nil? || src.empty? hsh[package_name] ||= [] hsh[package_name] << File.join(Licensed::Git.repository_root, src) end end |
#sources_license_path(sources) ⇒ Object
Returns the top-most directory that is common to all paths in ‘sources`
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/licensed/source/manifest.rb', line 30 def sources_license_path(sources) common_prefix = Pathname.common_prefix(*sources).to_path # don't allow the repo root to be used as common prefix # the project this is run for should be excluded from the manifest, # or ignored in the config. any license in the root should be ignored. return common_prefix if common_prefix != Licensed::Git.repository_root # use the first source file as the license path. sources.first end |
#type ⇒ Object
15 16 17 |
# File 'lib/licensed/source/manifest.rb', line 15 def type "manifest" end |