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:, original_requirement: nil, platform: nil, type: nil, direct: nil, deprecated: nil, local: nil, optional: nil, original_name: nil, source: nil) ⇒ Dependency

Returns a new instance of Dependency.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bibliothecary/dependency.rb', line 40

def initialize(
  name:,
  requirement:,
  original_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
  @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



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

def deprecated
  @deprecated
end

#directBoolean (readonly)

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

Returns:

  • (Boolean)

    the current value of direct



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

def direct
  @direct
end

#localBoolean (readonly)

Is this dependency local? (default: nil)

Returns:

  • (Boolean)

    the current value of local



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

def local
  @local
end

#nameString (readonly)

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

Returns:

  • (String)

    the current value of name



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

def name
  @name
end

#optionalBoolean (readonly)

Is this dependency optional? (default: nil)

Returns:

  • (Boolean)

    the current value of optional



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

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



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

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



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

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



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

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



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

def requirement
  @requirement
end

#typeString (readonly)

The type of dependency, e.g. “runtime” or “test”

Returns:

  • (String)

    the current value of type



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

def type
  @type
end

Instance Method Details

#[](key) ⇒ Object



71
72
73
# File 'lib/bibliothecary/dependency.rb', line 71

def [](key)
  public_send(key)
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


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

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

#hashObject



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

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

#to_hObject



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

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