Class: Bibliothecary::Dependency
- Inherits:
-
Object
- Object
- Bibliothecary::Dependency
- Defined in:
- lib/bibliothecary/dependency.rb
Overview
Dependency represents a single unique dependency that was parsed out of a manifest.
Constant Summary collapse
- FIELDS =
i[ name requirement original_requirement platform type direct deprecated local optional original_name source ].freeze
Instance Attribute Summary collapse
-
#deprecated ⇒ Boolean
readonly
Is this dependency deprecated? (default: nil).
-
#direct ⇒ Boolean
readonly
Is this dependency a direct dependency (vs transitive dependency)? (default: nil).
-
#local ⇒ Boolean
readonly
Is this dependency local? (default: nil).
-
#name ⇒ String
readonly
The name of the package, e.g.
-
#optional ⇒ Boolean
readonly
Is this dependency optional? (default: nil).
-
#original_name ⇒ String
readonly
The original name used to require the dependency, for cases where it did not match the resolved name.
-
#original_requirement ⇒ String
readonly
The original requirement used to require the dependency, for cases where it did not match the resolved name.
-
#platform ⇒ String
readonly
The platform of the package, e.g.
-
#requirement ⇒ String
readonly
The version requirement of the release, e.g.
-
#type ⇒ String
readonly
The type or scope of dependency, e.g.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(name:, requirement:, platform:, original_requirement: nil, type: nil, direct: nil, deprecated: nil, local: nil, optional: nil, original_name: nil, source: nil) ⇒ Dependency
constructor
A new instance of Dependency.
- #to_h ⇒ Object
Constructor Details
#initialize(name:, requirement:, platform:, original_requirement: nil, type: nil, direct: nil, deprecated: nil, local: nil, optional: nil, original_name: nil, source: nil) ⇒ Dependency
Returns a new instance of Dependency.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bibliothecary/dependency.rb', line 41 def initialize( name:, requirement:, platform:, original_requirement: nil, type: nil, direct: nil, deprecated: nil, local: nil, optional: nil, original_name: nil, source: nil ) @name = name @platform = platform @requirement = requirement || "*" @original_requirement = original_requirement @type = type @direct = direct @deprecated = deprecated @local = local @optional = optional @original_name = original_name @source = source end |
Instance Attribute Details
#deprecated ⇒ Boolean (readonly)
Is this dependency deprecated? (default: nil)
24 25 26 |
# File 'lib/bibliothecary/dependency.rb', line 24 def deprecated @deprecated end |
#direct ⇒ Boolean (readonly)
Is this dependency a direct dependency (vs transitive dependency)? (default: nil)
24 25 26 |
# File 'lib/bibliothecary/dependency.rb', line 24 def direct @direct end |
#local ⇒ Boolean (readonly)
Is this dependency local? (default: nil)
24 25 26 |
# File 'lib/bibliothecary/dependency.rb', line 24 def local @local end |
#name ⇒ String (readonly)
The name of the package, e.g. “ansi-string-colors”
24 25 26 |
# File 'lib/bibliothecary/dependency.rb', line 24 def name @name end |
#optional ⇒ Boolean (readonly)
Is this dependency optional? (default: nil)
24 25 26 |
# File 'lib/bibliothecary/dependency.rb', line 24 def optional @optional end |
#original_name ⇒ String (readonly)
The original name used to require the dependency, for cases where it did not match the resolved name. This can be used for features like aliasing.
24 25 26 |
# File 'lib/bibliothecary/dependency.rb', line 24 def original_name @original_name end |
#original_requirement ⇒ String (readonly)
The original requirement used to require the dependency, for cases where it did not match the resolved name. This can be used for features like aliasing.
24 25 26 |
# File 'lib/bibliothecary/dependency.rb', line 24 def original_requirement @original_requirement end |
#platform ⇒ String (readonly)
The platform of the package, e.g. “maven”. This is optional because it’s implicit in most parser results, and the analyzer returns the platform name itself. One exception are multi-parsers like DependenciesCSV, because they may return deps from multiple platforms. Bibliothecary could start returning this field for all deps in future, and make it required. (default: nil)
24 25 26 |
# File 'lib/bibliothecary/dependency.rb', line 24 def platform @platform end |
#requirement ⇒ String (readonly)
The version requirement of the release, e.g. “1.0.0” or “^1.0.0”
24 25 26 |
# File 'lib/bibliothecary/dependency.rb', line 24 def requirement @requirement end |
#type ⇒ String (readonly)
The type or scope of dependency, e.g. “runtime” or “test”. In some ecosystems a default may be set and in other ecosystems it may make sense to return nil when not found.
24 25 26 |
# File 'lib/bibliothecary/dependency.rb', line 24 def type @type end |
Instance Method Details
#[](key) ⇒ Object
72 73 74 |
# File 'lib/bibliothecary/dependency.rb', line 72 def [](key) public_send(key) end |
#eql?(other) ⇒ Boolean Also known as: ==
67 68 69 |
# File 'lib/bibliothecary/dependency.rb', line 67 def eql?(other) FIELDS.all? { |f| public_send(f) == other.public_send(f) } end |
#hash ⇒ Object
80 81 82 |
# File 'lib/bibliothecary/dependency.rb', line 80 def hash FIELDS.map { |f| public_send(f) }.hash end |
#to_h ⇒ Object
76 77 78 |
# File 'lib/bibliothecary/dependency.rb', line 76 def to_h FIELDS.to_h { |f| [f, public_send(f)] } end |