Class: Licensed::Sources::Cargo
- Defined in:
- lib/licensed/sources/cargo.rb
Instance Attribute Summary
Attributes inherited from Source
Instance Method Summary collapse
-
#cargo_metadata ⇒ Object
Returns parsed JSON metadata returned from the cargo CLI.
-
#cargo_metadata_command ⇒ Object
Runs a command to get cargo metadata for the current package.
-
#cargo_metadata_packages ⇒ Object
Returns a hash of id => package pairs sourced from the “packages” cargo metadata property.
-
#cargo_metadata_resolved_node_ids ⇒ Object
Returns the ids of all resolved nodes used to build the current package.
-
#cargo_metadata_workspace_members ⇒ Object
Returns a set of the ids of packages in the current workspace.
-
#enabled? ⇒ Boolean
Source is enabled when the cargo tool and Cargo.toml manifest file are available.
- #enumerate_dependencies ⇒ Object
-
#packages ⇒ Object
Returns the package data for all dependencies used to build the current package.
Methods inherited from Source
#dependencies, full_type, #ignored?, inherited, #initialize, register_source, require_matched_dependency_version, #source_config, type, type_and_version
Constructor Details
This class inherits a constructor from Licensed::Sources::Source
Instance Method Details
#cargo_metadata ⇒ Object
Returns parsed JSON metadata returned from the cargo CLI
56 57 58 59 60 61 |
# File 'lib/licensed/sources/cargo.rb', line 56 def @cargo_metadata ||= JSON.parse() rescue JSON::ParserError => e = "Licensed was unable to parse the output from 'cargo metadata'. JSON Error: #{e.}" raise Licensed::Sources::Source::Error, end |
#cargo_metadata_command ⇒ Object
Runs a command to get cargo metadata for the current package
64 65 66 67 |
# File 'lib/licensed/sources/cargo.rb', line 64 def = Array(config.dig("cargo", "metadata_options")).flat_map(&:split) Licensed::Shell.execute("cargo", "metadata", "--format-version=1", *) end |
#cargo_metadata_packages ⇒ Object
Returns a hash of id => package pairs sourced from the “packages” cargo metadata property
44 45 46 47 48 |
# File 'lib/licensed/sources/cargo.rb', line 44 def @cargo_metadata_packages ||= ["packages"].each_with_object({}) do |package, hsh| hsh[package["id"]] = package end end |
#cargo_metadata_resolved_node_ids ⇒ Object
Returns the ids of all resolved nodes used to build the current package
36 37 38 39 40 41 |
# File 'lib/licensed/sources/cargo.rb', line 36 def .dig("resolve", "nodes") .map { |node| node["id"] } .reject { |id| .include?(id) } end |
#cargo_metadata_workspace_members ⇒ Object
Returns a set of the ids of packages in the current workspace
51 52 53 |
# File 'lib/licensed/sources/cargo.rb', line 51 def @cargo_metadata_workspace_members ||= Set.new(Array(["workspace_members"])) end |
#enabled? ⇒ Boolean
Source is enabled when the cargo tool and Cargo.toml manifest file are available
9 10 11 12 |
# File 'lib/licensed/sources/cargo.rb', line 9 def enabled? return false unless Licensed::Shell.tool_available?("cargo") config.pwd.join("Cargo.toml").exist? end |
#enumerate_dependencies ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/licensed/sources/cargo.rb', line 14 def enumerate_dependencies packages.map do |package| Dependency.new( name: "#{package["name"]}-#{package["version"]}", version: package["version"], path: File.dirname(package["manifest_path"]), metadata: { "name" => package["name"], "type" => Cargo.type, "summary" => package["description"], "homepage" => package["homepage"] } ) end end |
#packages ⇒ Object
Returns the package data for all dependencies used to build the current package
31 32 33 |
# File 'lib/licensed/sources/cargo.rb', line 31 def packages .map { |id| [id] } end |