Class: Dependabot::Docker::Tag
- Inherits:
-
Object
- Object
- Dependabot::Docker::Tag
- Defined in:
- lib/dependabot/docker/tag.rb
Constant Summary collapse
- WORDS_WITH_BUILD =
/(?:(?:-[a-z]+)+-[0-9]+)+/
- VERSION_REGEX =
/v?(?<version>[0-9]+(?:\.[0-9]+)*(?:_[0-9]+|\.[a-z0-9]+|#{WORDS_WITH_BUILD}|-(?:kb)?[0-9]+)*)/i
- VERSION_WITH_SFX =
/^#{VERSION_REGEX}(?<suffix>-[a-z][a-z0-9.\-]*)?$/i
- VERSION_WITH_PFX =
/^(?<prefix>[a-z][a-z0-9.\-_]*-)?#{VERSION_REGEX}$/i
- VERSION_WITH_PFX_AND_SFX =
/^(?<prefix>[a-z\-_]+-)?#{VERSION_REGEX}(?<suffix>-[a-z\-]+)?$/i
- NAME_WITH_VERSION =
/ #{VERSION_WITH_PFX}| #{VERSION_WITH_SFX}| #{VERSION_WITH_PFX_AND_SFX} /x
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #canonical? ⇒ Boolean
- #comparable? ⇒ Boolean
- #comparable_to?(other) ⇒ Boolean
- #digest? ⇒ Boolean
- #format ⇒ Object
-
#initialize(name) ⇒ Tag
constructor
A new instance of Tag.
- #looks_like_prerelease? ⇒ Boolean
- #numeric_version ⇒ Object
- #precision ⇒ Object
- #prefix ⇒ Object
- #same_but_less_precise?(other) ⇒ Boolean
- #same_precision?(other) ⇒ Boolean
- #segments ⇒ Object
- #suffix ⇒ Object
- #to_s ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(name) ⇒ Tag
Returns a new instance of Tag.
23 24 25 |
# File 'lib/dependabot/docker/tag.rb', line 23 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/dependabot/docker/tag.rb', line 21 def name @name end |
Instance Method Details
#canonical? ⇒ Boolean
68 69 70 71 72 73 74 75 76 |
# File 'lib/dependabot/docker/tag.rb', line 68 def canonical? return false unless numeric_version return true if name == numeric_version # .NET tags are suffixed with -sdk return true if name == numeric_version + "-sdk" name == "jdk-" + numeric_version end |
#comparable? ⇒ Boolean
54 55 56 |
# File 'lib/dependabot/docker/tag.rb', line 54 def comparable? name.match?(NAME_WITH_VERSION) end |
#comparable_to?(other) ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dependabot/docker/tag.rb', line 39 def comparable_to?(other) return false unless comparable? other_prefix = other.prefix other_suffix = other.suffix other_format = other.format equal_prefix = prefix == other_prefix equal_format = format == other_format return equal_prefix && equal_format if other_format == :sha_suffixed equal_suffix = suffix == other_suffix equal_prefix && equal_format && equal_suffix end |
#digest? ⇒ Boolean
31 32 33 |
# File 'lib/dependabot/docker/tag.rb', line 31 def digest? name.match?(FileParser::DIGEST) end |
#format ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/dependabot/docker/tag.rb', line 90 def format return :sha_suffixed if name.match?(/(^|\-g?)[0-9a-f]{7,}$/) return :year_month if version.match?(/^[12]\d{3}(?:[.\-]|$)/) return :year_month_day if version.match?(/^[12](?:\d{5}|\d{7})(?:[.\-]|$)/) return :build_num if version.match?(/^\d+$/) # As an example, "21-ea-32", "22-ea-7", and "22-ea-jdk-nanoserver-1809" # are mapped to "<version>-ea-<build_num>", "<version>-ea-<build_num>", # and "<version>-ea-jdk-nanoserver-<build_num>" respectively. # # That means only "22-ea-7" will be considered as a viable update # candidate for "21-ea-32", since it's the only one that respects that # format. if version.match?(WORDS_WITH_BUILD) return :"<version>#{version.match(WORDS_WITH_BUILD).to_s.gsub(/-[0-9]+/, '-<build_num>')}" end :normal end |
#looks_like_prerelease? ⇒ Boolean
35 36 37 |
# File 'lib/dependabot/docker/tag.rb', line 35 def looks_like_prerelease? numeric_version.match?(/[a-zA-Z]/) end |
#numeric_version ⇒ Object
110 111 112 113 114 |
# File 'lib/dependabot/docker/tag.rb', line 110 def numeric_version return unless comparable? version.gsub(/kb/i, "").gsub(/-[a-z]+/, "").downcase end |
#precision ⇒ Object
116 117 118 |
# File 'lib/dependabot/docker/tag.rb', line 116 def precision segments.length end |
#prefix ⇒ Object
78 79 80 |
# File 'lib/dependabot/docker/tag.rb', line 78 def prefix name.match(NAME_WITH_VERSION).named_captures.fetch("prefix") end |
#same_but_less_precise?(other) ⇒ Boolean
62 63 64 65 66 |
# File 'lib/dependabot/docker/tag.rb', line 62 def same_but_less_precise?(other) other.segments.zip(segments).all? do |segment, other_segment| segment == other_segment || other_segment.nil? end end |
#same_precision?(other) ⇒ Boolean
58 59 60 |
# File 'lib/dependabot/docker/tag.rb', line 58 def same_precision?(other) other.precision == precision end |
#segments ⇒ Object
120 121 122 |
# File 'lib/dependabot/docker/tag.rb', line 120 def segments numeric_version.split(/[.-]/) end |
#suffix ⇒ Object
82 83 84 |
# File 'lib/dependabot/docker/tag.rb', line 82 def suffix name.match(NAME_WITH_VERSION).named_captures.fetch("suffix") end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/dependabot/docker/tag.rb', line 27 def to_s name end |
#version ⇒ Object
86 87 88 |
# File 'lib/dependabot/docker/tag.rb', line 86 def version name.match(NAME_WITH_VERSION).named_captures.fetch("version") end |