Class: Dependabot::Ecosystem::VersionManager

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/dependabot/ecosystem.rb

Constant Summary collapse

DEFAULT_VERSION_PATTERN =
/(\d+\.\d+(.\d+)*)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, detected_version: nil, version: nil, deprecated_versions: [], supported_versions: [], requirement: nil) ⇒ VersionManager

Returns a new instance of VersionManager.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/dependabot/ecosystem.rb', line 41

def initialize(
  name:,
  detected_version: nil,
  version: nil,
  deprecated_versions: [],
  supported_versions: [],
  requirement: nil
)
  @name = T.let(name, String)
  @detected_version = T.let(detected_version || version, T.nilable(Dependabot::Version))
  @version = T.let(version, T.nilable(Dependabot::Version))
  @deprecated_versions = T.let(deprecated_versions, T::Array[Dependabot::Version])
  @supported_versions = T.let(supported_versions, T::Array[Dependabot::Version])
  @requirement = T.let(requirement, T.nilable(Dependabot::Requirement))
end

Instance Attribute Details

#deprecated_versionsObject (readonly)

Returns the value of attribute deprecated_versions.



79
80
81
# File 'lib/dependabot/ecosystem.rb', line 79

def deprecated_versions
  @deprecated_versions
end

#detected_versionObject (readonly)

Returns the value of attribute detected_version.



67
68
69
# File 'lib/dependabot/ecosystem.rb', line 67

def detected_version
  @detected_version
end

#nameObject (readonly)

Returns the value of attribute name.



61
62
63
# File 'lib/dependabot/ecosystem.rb', line 61

def name
  @name
end

#requirementObject (readonly)

Returns the value of attribute requirement.



91
92
93
# File 'lib/dependabot/ecosystem.rb', line 91

def requirement
  @requirement
end

#supported_versionsObject (readonly)

Returns the value of attribute supported_versions.



83
84
85
# File 'lib/dependabot/ecosystem.rb', line 83

def supported_versions
  @supported_versions
end

#versionObject (readonly)

Returns the value of attribute version.



73
74
75
# File 'lib/dependabot/ecosystem.rb', line 73

def version
  @version
end

Instance Method Details

#deprecated?Boolean

Returns:

  • (Boolean)


114
115
116
117
118
119
120
121
# File 'lib/dependabot/ecosystem.rb', line 114

def deprecated?
  return false unless detected_version

  # If the version is unsupported, the unsupported error is getting raised separately.
  return false if unsupported?

  deprecated_versions.include?(detected_version)
end

#raise_if_unsupported!Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/dependabot/ecosystem.rb', line 139

def raise_if_unsupported!
  return unless detected_version

  return unless unsupported?

  # Example: v2.*, v3.*
  supported_versions_message = supported_versions.map { |v| "v#{v}.*" }.join(", ")

  raise ToolVersionNotSupported.new(
    name,
    detected_version.to_s,
    supported_versions_message
  )
end

#support_later_versions?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/dependabot/ecosystem.rb', line 159

def support_later_versions?
  false
end

#unsupported?Boolean

Returns:

  • (Boolean)


127
128
129
130
131
132
133
134
# File 'lib/dependabot/ecosystem.rb', line 127

def unsupported?
  return false unless detected_version

  return false if supported_versions.empty?

  # Check if the version is not supported
  supported_versions.all? { |supported| supported > detected_version }
end

#version_to_raw_sObject



105
106
107
# File 'lib/dependabot/ecosystem.rb', line 105

def version_to_raw_s
  version&.to_semver.to_s
end

#version_to_sObject



97
98
99
# File 'lib/dependabot/ecosystem.rb', line 97

def version_to_s
  version.to_s
end