Class: Bibliothecary::Dependency

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#deprecatedBoolean (readonly)

Is this dependency deprecated? (default: nil)

Returns:

  • (Boolean)

    the current value of deprecated



24
25
26
# File 'lib/bibliothecary/dependency.rb', line 24

def deprecated
  @deprecated
end

#directBoolean (readonly)

Is this dependency a direct dependency (vs transitive dependency)? (default: nil)

Returns:

  • (Boolean)

    the current value of direct



24
25
26
# File 'lib/bibliothecary/dependency.rb', line 24

def direct
  @direct
end

#localBoolean (readonly)

Is this dependency local? (default: nil)

Returns:

  • (Boolean)

    the current value of local



24
25
26
# File 'lib/bibliothecary/dependency.rb', line 24

def local
  @local
end

#nameString (readonly)

The name of the package, e.g. “ansi-string-colors”

Returns:

  • (String)

    the current value of name



24
25
26
# File 'lib/bibliothecary/dependency.rb', line 24

def name
  @name
end

#optionalBoolean (readonly)

Is this dependency optional? (default: nil)

Returns:

  • (Boolean)

    the current value of optional



24
25
26
# File 'lib/bibliothecary/dependency.rb', line 24

def optional
  @optional
end

#original_nameString (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.

Returns:

  • (String)

    the current value of original_name



24
25
26
# File 'lib/bibliothecary/dependency.rb', line 24

def original_name
  @original_name
end

#original_requirementString (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.

Returns:

  • (String)

    the current value of original_requirement



24
25
26
# File 'lib/bibliothecary/dependency.rb', line 24

def original_requirement
  @original_requirement
end

#platformString (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)

Returns:

  • (String)

    the current value of platform



24
25
26
# File 'lib/bibliothecary/dependency.rb', line 24

def platform
  @platform
end

#requirementString (readonly)

The version requirement of the release, e.g. “1.0.0” or “^1.0.0”

Returns:

  • (String)

    the current value of requirement



24
25
26
# File 'lib/bibliothecary/dependency.rb', line 24

def requirement
  @requirement
end

#typeString (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.

Returns:

  • (String)

    the current value of type



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: ==

Returns:

  • (Boolean)


67
68
69
# File 'lib/bibliothecary/dependency.rb', line 67

def eql?(other)
  FIELDS.all? { |f| public_send(f) == other.public_send(f) }
end

#hashObject



80
81
82
# File 'lib/bibliothecary/dependency.rb', line 80

def hash
  FIELDS.map { |f| public_send(f) }.hash
end

#to_hObject



76
77
78
# File 'lib/bibliothecary/dependency.rb', line 76

def to_h
  FIELDS.to_h { |f| [f, public_send(f)] }
end