Class: Licensed::Sources::Dep
- Defined in:
- lib/licensed/sources/dep.rb
Instance Attribute Summary
Attributes inherited from Source
Instance Method Summary collapse
- #enabled? ⇒ Boolean
- #enumerate_dependencies ⇒ Object
- #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
-
#packages ⇒ Object
Returns an array of dependency packages specified from Gopkg.lock.
Methods inherited from Source
#dependencies, #ignored?, inherited, #initialize, type
Constructor Details
This class inherits a constructor from Licensed::Sources::Source
Instance Method Details
#enabled? ⇒ Boolean
7 8 9 |
# File 'lib/licensed/sources/dep.rb', line 7 def enabled? go_dep_available? end |
#enumerate_dependencies ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/licensed/sources/dep.rb', line 11 def enumerate_dependencies packages.map do |package| package_dir = @config.pwd.join("vendor", package[:name]) search_root = @config.pwd.join("vendor", package[:project]) Dependency.new( name: package[:name], version: package[:version], path: package_dir.to_s, search_root: search_root.to_s, metadata: { "type" => Dep.type, "homepage" => "https://#{package[:name]}" } ) end end |
#go_dep_available? ⇒ Boolean
50 51 52 |
# File 'lib/licensed/sources/dep.rb', line 50 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/*”
46 47 48 |
# File 'lib/licensed/sources/dep.rb', line 46 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
59 60 61 62 63 64 |
# File 'lib/licensed/sources/dep.rb', line 59 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
54 55 56 |
# File 'lib/licensed/sources/dep.rb', line 54 def gopkg_lock_path @config.pwd.join("Gopkg.lock") end |
#packages ⇒ Object
Returns an array of dependency packages specified from Gopkg.lock
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/licensed/sources/dep.rb', line 30 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 |