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 =
[
  :name,
  :requirement,
  :original_requirement,
  :platform,
  :type,
  :direct,
  :deprecated,
  :local,
  :optional,
  :original_name,
  :source,
]

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.



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

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



21
22
23
# File 'lib/bibliothecary/dependency.rb', line 21

def deprecated
  @deprecated
end

#directBoolean (readonly)

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

Returns:

  • (Boolean)

    the current value of direct



21
22
23
# File 'lib/bibliothecary/dependency.rb', line 21

def direct
  @direct
end

#localBoolean (readonly)

Is this dependency local? (default: nil)

Returns:

  • (Boolean)

    the current value of local



21
22
23
# File 'lib/bibliothecary/dependency.rb', line 21

def local
  @local
end

#nameString (readonly)

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

Returns:

  • (String)

    the current value of name



21
22
23
# File 'lib/bibliothecary/dependency.rb', line 21

def name
  @name
end

#optionalBoolean (readonly)

Is this dependency optional? (default: nil)

Returns:

  • (Boolean)

    the current value of optional



21
22
23
# File 'lib/bibliothecary/dependency.rb', line 21

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



21
22
23
# File 'lib/bibliothecary/dependency.rb', line 21

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



21
22
23
# File 'lib/bibliothecary/dependency.rb', line 21

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



21
22
23
# File 'lib/bibliothecary/dependency.rb', line 21

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



21
22
23
# File 'lib/bibliothecary/dependency.rb', line 21

def requirement
  @requirement
end

#typeString (readonly)

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

Returns:

  • (String)

    the current value of type



21
22
23
# File 'lib/bibliothecary/dependency.rb', line 21

def type
  @type
end

Instance Method Details

#[](key) ⇒ Object



69
70
71
# File 'lib/bibliothecary/dependency.rb', line 69

def [](key)
  public_send(key)
end

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

Returns:

  • (Boolean)


64
65
66
# File 'lib/bibliothecary/dependency.rb', line 64

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

#hashObject



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

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

#to_hObject



73
74
75
# File 'lib/bibliothecary/dependency.rb', line 73

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