Class: Licensed::Source::Dep
- Inherits:
-
Object
- Object
- Licensed::Source::Dep
- Defined in:
- lib/licensed/source/dep.rb
Class Method Summary collapse
Instance Method Summary collapse
- #dependencies ⇒ Object
- #enabled? ⇒ Boolean
- #go_dep_available? ⇒ Boolean
-
#go_std_package?(import_path) ⇒ Boolean
Returns whether the package is part of the go std list.
-
#go_std_packages ⇒ Object
Returns a list of go standard packages.
- #gopkg_lock_path ⇒ Object
-
#initialize(config) ⇒ Dep
constructor
A new instance of Dep.
-
#packages ⇒ Object
Returns an array of dependency packages specified from Gopkg.lock.
Constructor Details
#initialize(config) ⇒ Dep
11 12 13 |
# File 'lib/licensed/source/dep.rb', line 11 def initialize(config) @config = config end |
Class Method Details
.type ⇒ Object
7 8 9 |
# File 'lib/licensed/source/dep.rb', line 7 def self.type "dep" end |
Instance Method Details
#dependencies ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/licensed/source/dep.rb', line 19 def dependencies @dependencies ||= begin packages.map do |package| package_dir = @config.pwd.join("vendor", package[:name]) search_root = @config.pwd.join("vendor", package[:project]) unless package_dir.exist? next if @config.ignored?("type" => Dep.type, "name" => package[:name]) raise "couldn't find package for #{package[:name]}" end Dependency.new(package_dir.to_s, { "type" => Dep.type, "name" => package[:name], "homepage" => "https://#{package[:name]}", "search_root" => search_root.to_s, "version" => package[:version] }) end end end |
#enabled? ⇒ Boolean
15 16 17 |
# File 'lib/licensed/source/dep.rb', line 15 def enabled? go_dep_available? end |
#go_dep_available? ⇒ Boolean
62 63 64 |
# File 'lib/licensed/source/dep.rb', line 62 def go_dep_available? gopkg_lock_path.exist? end |
#go_std_package?(import_path) ⇒ Boolean
Returns whether the package is part of the go std list. Replaces “golang.org” with “golang_org” to match packages listed in ‘go list std` as “vendor/golang_org/*” but are vendored as “vendor/golang.org/*”
58 59 60 |
# File 'lib/licensed/source/dep.rb', line 58 def go_std_package?(import_path) go_std_packages.include? "vendor/#{import_path.sub(/^golang.org/, "golang_org")}" end |
#go_std_packages ⇒ Object
Returns a list of go standard packages
71 72 73 74 75 76 |
# File 'lib/licensed/source/dep.rb', line 71 def go_std_packages @std_packages ||= begin return [] unless Licensed::Shell.tool_available?("go") Licensed::Shell.execute("go", "list", "std").lines.map(&:strip) end end |
#gopkg_lock_path ⇒ Object
66 67 68 |
# File 'lib/licensed/source/dep.rb', line 66 def gopkg_lock_path @config.pwd.join("Gopkg.lock") end |
#packages ⇒ Object
Returns an array of dependency packages specified from Gopkg.lock
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/licensed/source/dep.rb', line 42 def packages gopkg_lock = Tomlrb.load_file(gopkg_lock_path, symbolize_keys: true) return [] unless gopkg_lock && gopkg_lock[:projects] gopkg_lock[:projects].flat_map do |project| # map each package to a full import path # then return a hash for each import path containing the path and the version project[:packages].map { |package| package == "." ? project[:name] : "#{project[:name]}/#{package}" } .reject { |import_path| go_std_package?(import_path) } .map { |import_path| { name: import_path, version: project[:revision], project: project[:name] } } end end |