Class: Spandx::Core::Dependency
- Inherits:
-
Object
- Object
- Spandx::Core::Dependency
- Defined in:
- lib/spandx/core/dependency.rb
Constant Summary collapse
- PACKAGE_MANAGERS =
{ Spandx::Dotnet::Parsers::Csproj => :nuget, Spandx::Dotnet::Parsers::PackagesConfig => :nuget, Spandx::Dotnet::Parsers::Sln => :nuget, Spandx::Java::Parsers::Maven => :maven, Spandx::Js::Parsers::Npm => :npm, Spandx::Js::Parsers::Yarn => :yarn, Spandx::Php::Parsers::Composer => :composer, Spandx::Python::Parsers::PipfileLock => :pypi, Spandx::Ruby::Parsers::GemfileLock => :rubygems, Spandx::Os::Parsers::Apk => :apk, Spandx::Os::Parsers::Dpkg => :dpkg, Spandx::Terraform::Parsers::LockFile => :terraform, }.freeze
Instance Attribute Summary collapse
-
#licenses ⇒ Object
readonly
Returns the value of attribute licenses.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name:, version:, path:, meta: {}) ⇒ Dependency
constructor
A new instance of Dependency.
- #inspect ⇒ Object
- #package_manager ⇒ Object
- #to_a ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name:, version:, path:, meta: {}) ⇒ Dependency
Returns a new instance of Dependency.
22 23 24 25 26 27 28 |
# File 'lib/spandx/core/dependency.rb', line 22 def initialize(name:, version:, path:, meta: {}) @path = Pathname.new(path).realpath @name = name || @path.basename.to_s @version = version || @path.mtime.to_i.to_s @licenses = [] @meta = end |
Instance Attribute Details
#licenses ⇒ Object (readonly)
Returns the value of attribute licenses.
20 21 22 |
# File 'lib/spandx/core/dependency.rb', line 20 def licenses @licenses end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
20 21 22 |
# File 'lib/spandx/core/dependency.rb', line 20 def @meta end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/spandx/core/dependency.rb', line 20 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
20 21 22 |
# File 'lib/spandx/core/dependency.rb', line 20 def path @path end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
20 21 22 |
# File 'lib/spandx/core/dependency.rb', line 20 def version @version end |
Instance Method Details
#<=>(other) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/spandx/core/dependency.rb', line 34 def <=>(other) return 1 if other.nil? score = (name <=> other.name) score = score.zero? ? (version <=> other&.version) : score score.zero? ? (path.to_s <=> other&.path.to_s) : score end |
#==(other) ⇒ Object
46 47 48 |
# File 'lib/spandx/core/dependency.rb', line 46 def ==(other) eql?(other) end |
#eql?(other) ⇒ Boolean
50 51 52 |
# File 'lib/spandx/core/dependency.rb', line 50 def eql?(other) to_s == other.to_s end |
#hash ⇒ Object
42 43 44 |
# File 'lib/spandx/core/dependency.rb', line 42 def hash to_s.hash end |
#inspect ⇒ Object
58 59 60 |
# File 'lib/spandx/core/dependency.rb', line 58 def inspect "#<#{self.class} name=#{name} version=#{version} path=#{relative_path}>" end |
#package_manager ⇒ Object
30 31 32 |
# File 'lib/spandx/core/dependency.rb', line 30 def package_manager PACKAGE_MANAGERS[Parser.for(path).class] end |
#to_a ⇒ Object
62 63 64 |
# File 'lib/spandx/core/dependency.rb', line 62 def to_a [name, version, license_expression, relative_path.to_s] end |
#to_h ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/spandx/core/dependency.rb', line 66 def to_h { name: name, version: version, licenses: license_expression, path: relative_path.to_s } end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/spandx/core/dependency.rb', line 54 def to_s @to_s ||= [name, version, path].compact.join(' ') end |