Class: Dependabot::Maven::NewVersion

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

Constant Summary collapse

PRERELEASE_QUALIFIERS =
T.let([
  Dependabot::Maven::VersionParser::ALPHA,
  Dependabot::Maven::VersionParser::BETA,
  Dependabot::Maven::VersionParser::MILESTONE,
  Dependabot::Maven::VersionParser::RC,
  Dependabot::Maven::VersionParser::SNAPSHOT
].freeze, T::Array[Integer])

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ NewVersion

Returns a new instance of NewVersion.



38
39
40
41
# File 'lib/dependabot/maven/new_version.rb', line 38

def initialize(version)
  @version_string = T.let(version, String)
  @token_bucket = T.let(Dependabot::Maven::VersionParser.parse(version), Dependabot::Maven::TokenBucket)
end

Instance Attribute Details

#token_bucketObject

Returns the value of attribute token_bucket.



25
26
27
# File 'lib/dependabot/maven/new_version.rb', line 25

def token_bucket
  @token_bucket
end

Class Method Details

.correct?(version) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
# File 'lib/dependabot/maven/new_version.rb', line 28

def self.correct?(version)
  return false if version.empty?

  Dependabot::Maven::VersionParser.parse(version.to_s).to_a.any?
rescue Dependabot::BadRequirementError
  Dependabot.logger.info("Malformed version string - #{version}")
  false
end

Instance Method Details

#<=>(other) ⇒ Object



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

def <=>(other)
  T.must(token_bucket <=> other.token_bucket)
end

#inspectObject



44
45
46
# File 'lib/dependabot/maven/new_version.rb', line 44

def inspect
  "#<#{self.class} #{version_string}>"
end

#prerelease?Boolean

Returns:

  • (Boolean)


54
55
56
57
58
# File 'lib/dependabot/maven/new_version.rb', line 54

def prerelease?
  token_bucket.to_a.flatten.any? do |token|
    token.is_a?(Integer) && token.negative?
  end
end

#to_sObject



49
50
51
# File 'lib/dependabot/maven/new_version.rb', line 49

def to_s
  version_string
end