Class: Licensed::Source::Manifest
- Inherits:
-
Object
- Object
- Licensed::Source::Manifest
- Defined in:
- lib/licensed/source/manifest.rb
Instance Method Summary collapse
- #commit_date_command(sha) ⇒ Object
- #dependencies ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(config) ⇒ Manifest
constructor
A new instance of Manifest.
- #manifest ⇒ Object
- #manifest_path ⇒ Object
- #package_version(sources) ⇒ Object
- #packages ⇒ Object
- #repository_root ⇒ Object
- #source_version_command(source) ⇒ Object
- #sources_license_path(sources) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(config) ⇒ Manifest
Returns a new instance of Manifest.
6 7 8 |
# File 'lib/licensed/source/manifest.rb', line 6 def initialize(config) @config = config end |
Instance Method Details
#commit_date_command(sha) ⇒ Object
48 49 50 |
# File 'lib/licensed/source/manifest.rb', line 48 def commit_date_command(sha) `git show -s -1 --format=%ct #{sha}`.strip end |
#dependencies ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/licensed/source/manifest.rb', line 18 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
10 11 12 |
# File 'lib/licensed/source/manifest.rb', line 10 def enabled? @config.enabled?(type) && File.exist?(manifest_path) end |
#manifest ⇒ Object
64 65 66 |
# File 'lib/licensed/source/manifest.rb', line 64 def manifest JSON.parse(File.read(manifest_path)) end |
#manifest_path ⇒ Object
68 69 70 |
# File 'lib/licensed/source/manifest.rb', line 68 def manifest_path @config.path.join('manifest.json') end |
#package_version(sources) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/licensed/source/manifest.rb', line 40 def package_version(sources) return if sources.nil? || sources.empty? # return the latest version from the sources sources.map { |s| source_version_command(s) } .max_by { |sha| commit_date_command(sha) } end |
#packages ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/licensed/source/manifest.rb', line 56 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(repository_root, src) end end |
#repository_root ⇒ Object
72 73 74 |
# File 'lib/licensed/source/manifest.rb', line 72 def repository_root @root ||= `git rev-parse --show-toplevel`.strip end |
#source_version_command(source) ⇒ Object
52 53 54 |
# File 'lib/licensed/source/manifest.rb', line 52 def source_version_command(source) `git rev-list -1 HEAD -- #{source}`.strip end |
#sources_license_path(sources) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/licensed/source/manifest.rb', line 28 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 != repository_root # use the first source file as the license path. sources.first end |
#type ⇒ Object
14 15 16 |
# File 'lib/licensed/source/manifest.rb', line 14 def type 'manifest' end |