Class: Dependabot::NpmAndYarn::Version

Inherits:
Gem::Version
  • Object
show all
Defined in:
lib/dependabot/npm_and_yarn/version.rb

Constant Summary collapse

VERSION_PATTERN =
Gem::Version::VERSION_PATTERN + '(\+[0-9a-zA-Z\-.]+)?'
ANCHORED_VERSION_PATTERN =
/\A\s*(#{VERSION_PATTERN})?\s*\z/.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ Version

Returns a new instance of Version.



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

def initialize(version)
  @version_string = version.to_s
  version = version.gsub(/^v/, "") if version.is_a?(String)

  version, @build_info = version.to_s.split("+") if version.to_s.include?("+")

  super
end

Instance Attribute Details

#build_infoObject (readonly)

Returns the value of attribute build_info.



15
16
17
# File 'lib/dependabot/npm_and_yarn/version.rb', line 15

def build_info
  @build_info
end

Class Method Details

.correct?(version) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
# File 'lib/dependabot/npm_and_yarn/version.rb', line 20

def self.correct?(version)
  version = version.gsub(/^v/, "") if version.is_a?(String)

  return false if version.nil?

  version.to_s.match?(ANCHORED_VERSION_PATTERN)
end

Instance Method Details

#backwards_compatible_with?(other) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
# File 'lib/dependabot/npm_and_yarn/version.rb', line 49

def backwards_compatible_with?(other)
  case major
  when 0
    self == other
  else
    major == other.major && minor >= other.minor
  end
end

#inspectObject



62
63
64
# File 'lib/dependabot/npm_and_yarn/version.rb', line 62

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

#majorObject



37
38
39
# File 'lib/dependabot/npm_and_yarn/version.rb', line 37

def major
  @major ||= segments[0] || 0
end

#minorObject



41
42
43
# File 'lib/dependabot/npm_and_yarn/version.rb', line 41

def minor
  @minor ||= segments[1] || 0
end

#patchObject



45
46
47
# File 'lib/dependabot/npm_and_yarn/version.rb', line 45

def patch
  @patch ||= segments[2] || 0
end

#to_sObject



58
59
60
# File 'lib/dependabot/npm_and_yarn/version.rb', line 58

def to_s
  @version_string
end