Class: Homebrew::Livecheck::Strategy::RubyGems
- Extended by:
- Homebrew::Livecheck::Strategic
- Defined in:
- livecheck/strategy/ruby_gems.rb
Overview
The RubyGems strategy identifies the newest version of a RubyGems package by checking the latest version API endpoint for the gem.
RubyGems URLs have a standard format:
`https://rubygems.org/downloads/example-1.2.3.gem`
Constant Summary collapse
- DEFAULT_BLOCK =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
The default
strategyblock used to extract version information when astrategyblock isn't provided. T.let(proc do |json| json["version"] end.freeze, T.proc.params( arg0: T::Hash[String, T.anything], ).returns(T.any(String, T::Array[String])))
- FILENAME_REGEX =
/ (?<gem_name>.+)- # The gem name followed by a hyphen (?<version>\d+(?:\.[0-9A-Za-z]+)*) # The version string (?:-(?<platform>.+))? # The optional platform \.gem$ /ix- URL_MATCH_REGEX =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
The
Regexpused to determine if the strategy applies to the URL. %r{ ^https?://rubygems\.org /(?:downloads|gems/[^/]+/versions) /#{FILENAME_REGEX.source.strip} # The gem filename }ix
Class Method Summary collapse
-
.find_versions(url:, regex: nil, content: nil, options: Options.new, &block) ⇒ Hash{Symbol => T.anything}
private
Generates a RubyGems latest version API URL for the gem and identifies new versions using Json.find_versions with a block.
-
.generate_input_values(url) ⇒ Hash{Symbol => T.untyped}
private
Extracts the gem name from the provided URL and uses it to generate the RubyGems latest version API URL for the gem.
-
.match?(url) ⇒ Boolean
private
Whether the strategy can be applied to the provided URL.
Methods included from Homebrew::Livecheck::Strategic
Class Method Details
.find_versions(url:, regex: nil, content: nil, options: Options.new, &block) ⇒ Hash{Symbol => T.anything}
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Generates a RubyGems latest version API URL for the gem and identifies new versions using Json.find_versions with a block.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'livecheck/strategy/ruby_gems.rb', line 83 def self.find_versions(url:, regex: nil, content: nil, options: Options.new, &block) match_data = { matches: {}, regex:, url: } generated = generate_input_values(url) return match_data if generated.blank? Json.find_versions( url: generated[:url], regex:, content:, options:, &block || DEFAULT_BLOCK ) end |
.generate_input_values(url) ⇒ Hash{Symbol => T.untyped}
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Extracts the gem name from the provided URL and uses it to generate the RubyGems latest version API URL for the gem.
56 57 58 59 60 61 62 63 64 |
# File 'livecheck/strategy/ruby_gems.rb', line 56 def self.generate_input_values(url) values = {} return values unless (match = url.match(URL_MATCH_REGEX)) values[:url] = "https://rubygems.org/api/v1/versions/" \ "#{URI.encode_www_form_component(T.must(match[:gem_name]))}/latest.json" values end |
.match?(url) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Whether the strategy can be applied to the provided URL.
46 47 48 |
# File 'livecheck/strategy/ruby_gems.rb', line 46 def self.match?(url) URL_MATCH_REGEX.match?(url) end |