Class: Dependabot::NpmAndYarn::Version
- Inherits:
-
Version
- Object
- Version
- Dependabot::NpmAndYarn::Version
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/npm_and_yarn/version.rb
Constant Summary collapse
- VERSION_TAGS =
These are possible npm versioning tags that can be used in place of a version. See docs.npmjs.com/cli/v10/commands/npm-dist-tag#purpose for more details.
T.let([ "alpha", # Alpha version, early testing phase "beta", # Beta version, more stable than alpha "canary", # Canary version, often used for cutting-edge builds "dev", # Development version, ongoing development "experimental", # Experimental version, unstable and new features "latest", # Latest stable version, used by npm to identify the current version of a package "legacy", # Legacy version, older version maintained for compatibility "next", # Next version, used by some projects to identify the upcoming version "nightly", # Nightly build, daily builds often including latest changes "rc", # Release candidate, potential final version "release", # General release version "stable" # Stable version, thoroughly tested and stable ].freeze.map(&:freeze), T::Array[String])
- VERSION_PATTERN =
T.let(Gem::Version::VERSION_PATTERN + '(\+[0-9a-zA-Z\-.]+)?', String)
- ANCHORED_VERSION_PATTERN =
/\A\s*(#{VERSION_PATTERN})?\s*\z/
Instance Attribute Summary collapse
-
#build_info ⇒ Object
readonly
Returns the value of attribute build_info.
Class Method Summary collapse
Instance Method Summary collapse
- #backwards_compatible_with?(other) ⇒ Boolean
-
#initialize(version) ⇒ Version
constructor
A new instance of Version.
- #inspect ⇒ Object
- #major ⇒ Object
- #minor ⇒ Object
- #patch ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(version) ⇒ Version
Returns a new instance of Version.
64 65 66 67 68 69 70 71 72 |
# File 'lib/dependabot/npm_and_yarn/version.rb', line 64 def initialize(version) @version_string = T.let(version.to_s, String) version = version.gsub(/^v/, "") if version.is_a?(String) @build_info = T.let(nil, T.nilable(String)) version, @build_info = version.to_s.split("+") if version.to_s.include?("+") super(T.must(version)) end |
Instance Attribute Details
#build_info ⇒ Object (readonly)
Returns the value of attribute build_info.
20 21 22 |
# File 'lib/dependabot/npm_and_yarn/version.rb', line 20 def build_info @build_info end |
Class Method Details
.correct?(version) ⇒ Boolean
43 44 45 46 47 48 49 |
# File 'lib/dependabot/npm_and_yarn/version.rb', line 43 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 |
.new(version) ⇒ Object
75 76 77 |
# File 'lib/dependabot/npm_and_yarn/version.rb', line 75 def self.new(version) T.cast(super, Dependabot::NpmAndYarn::Version) end |
.semver_for(version) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dependabot/npm_and_yarn/version.rb', line 52 def self.semver_for(version) # The next two lines are to guard against improperly formatted # versions in a lockfile, such as an empty string or additional # characters. NPM/yarn fixes these when running an update, so we can # safely ignore these versions. return if version == "" return unless correct?(version) version end |
Instance Method Details
#backwards_compatible_with?(other) ⇒ Boolean
95 96 97 98 99 100 101 102 |
# File 'lib/dependabot/npm_and_yarn/version.rb', line 95 def backwards_compatible_with?(other) case major when 0 self == other else major == other.major && minor >= other.minor end end |
#inspect ⇒ Object
110 111 112 |
# File 'lib/dependabot/npm_and_yarn/version.rb', line 110 def inspect "#<#{self.class} #{@version_string}>" end |
#major ⇒ Object
80 81 82 |
# File 'lib/dependabot/npm_and_yarn/version.rb', line 80 def major @major ||= T.let(segments[0].to_i, T.nilable(Integer)) end |
#minor ⇒ Object
85 86 87 |
# File 'lib/dependabot/npm_and_yarn/version.rb', line 85 def minor @minor ||= T.let(segments[1].to_i, T.nilable(Integer)) end |
#patch ⇒ Object
90 91 92 |
# File 'lib/dependabot/npm_and_yarn/version.rb', line 90 def patch @patch ||= T.let(segments[2].to_i, T.nilable(Integer)) end |
#to_s ⇒ Object
105 106 107 |
# File 'lib/dependabot/npm_and_yarn/version.rb', line 105 def to_s @version_string end |