class GemUpdater::ChangelogParser
ChangelogParser
is responsible for parsing a source page where the gem code is hosted.
Constants
- MARKUP_FILES
Attributes
uri[R]
version[R]
Public Class Methods
new(uri:, version:)
click to toggle source
@param uri [String] uri of changelog @param version [String] version of gem
# File lib/gem_updater/changelog_parser.rb, line 17 def initialize(uri:, version:) @uri = uri @version = version end
Public Instance Methods
changelog()
click to toggle source
Get the changelog in an uri.
@return [String, nil] URL of changelog
# File lib/gem_updater/changelog_parser.rb, line 25 def changelog return uri unless changelog_may_contain_anchor? parse_changelog rescue OpenURI::HTTPError # Uri points to nothing log_error_and_return_uri("Cannot find #{uri}") rescue Errno::ETIMEDOUT # timeout log_error_and_return_uri("#{URI.parse(uri).host} is down") rescue ArgumentError => e # x-oauth-basic raises userinfo not supported. [RFC3986] log_error_and_return_uri(e) end
Private Instance Methods
changelog_may_contain_anchor?()
click to toggle source
Some documents like the one written in markdown may contain a direct anchor to specific version.
@return [Boolean] true if file may contain an anchor
# File lib/gem_updater/changelog_parser.rb, line 55 def changelog_may_contain_anchor? MARKUP_FILES.include?(File.extname(uri.to_s)) end
log_error_and_return_uri(error_message)
click to toggle source
# File lib/gem_updater/changelog_parser.rb, line 59 def log_error_and_return_uri(error_message) Bundler.ui.error error_message uri end
parse_changelog()
click to toggle source
Try to find where changelog might be.
@param doc [Nokogiri::XML::Element] document of source page
# File lib/gem_updater/changelog_parser.rb, line 42 def parse_changelog case URI.parse(uri).host when 'github.com' GithubParser.new(uri: uri, version: version).changelog else uri end end