class Bibliothecary::Dependency

Dependency represents a single unique dependency that was parsed out of a manifest.

@attr_reader [String] name The name of the package, e.g. “ansi-string-colors” @attr_reader [String] requirement The version requirement of the release, e.g. “1.0.0” or “^1.0.0” @attr_reader [String] platform 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)

@attr_reader [String] type The type of dependency, e.g. “runtime” or “test” @attr_reader [Boolean] direct Is this dependency a direct dependency (vs transitive dependency)? (default: nil) @attr_reader [Boolean] deprecated Is this dependency deprecated? (default: nil) @attr_reader [Boolean] local Is this dependency local? (default: nil) @attr_reader [Boolean] optional Is this dependency optional? (default: nil) @attr_reader [String] original_name 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.

@attr_reader [String] original_requirement 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.

@attr_reader [String] lockfile_requirement The requirement found in the lockfile, e.g. “1.0.0” or “^1.0.0”. This is

only returned from the yarn.lock parser and may not be used by downstream users. TODO: should this be deprecated?

@source [String] source An optional string to store the location of the manifest that contained this

dependency, e.g. "src/package.json".

Constants

FIELDS

Public Class Methods

new( name:, requirement:, original_requirement: nil, lockfile_requirement: nil, platform: nil, type: nil, direct: nil, deprecated: nil, local: nil, optional: nil, original_name: nil, source: nil ) click to toggle source
# File lib/bibliothecary/dependency.rb, line 41
def initialize(
  name:,
  requirement:,
  original_requirement: nil,
  lockfile_requirement: nil,
  platform: 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
  # TODO: maybe deprecate this field? Is it possible to replace it with original_requirement?
  @lockfile_requirement = lockfile_requirement
  @type = type
  @direct = direct
  @deprecated = deprecated
  @local = local
  @optional = optional
  @original_name = original_name
  @source = source
end

Public Instance Methods

==(other)
Alias for: eql?
[](key) click to toggle source
# File lib/bibliothecary/dependency.rb, line 75
def [](key)
  public_send(key)
end
eql?(other) click to toggle source
# File lib/bibliothecary/dependency.rb, line 70
def eql?(other)
  FIELDS.all? { |f| public_send(f) == other.public_send(f) }
end
Also aliased as: ==
hash() click to toggle source
# File lib/bibliothecary/dependency.rb, line 83
def hash
  FIELDS.map { |f| public_send(f) }.hash
end
to_h() click to toggle source
# File lib/bibliothecary/dependency.rb, line 79
def to_h
  FIELDS.to_h { |f| [f, public_send(f)] }
end