Class: GemUpdater::SourcePageParser

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_updater/source_page_parser.rb

Overview

SourcePageParser is responsible for parsing a source page where the gem code is hosted.

Direct Known Subclasses

GitHubParser

Defined Under Namespace

Classes: GitHubParser

Constant Summary collapse

HOSTS =
{
  github: /github.com/,
  bitbucket: /bitbucket.org/,
  rubygems: /rubygems.org/
}.freeze
MARKUP_FILES =
%w[.md .rdoc .textile].freeze
CHANGELOG_NAMES =
%w[changelog ChangeLog history changes news].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url: nil, version: nil) ⇒ SourcePageParser

Returns a new instance of SourcePageParser.

Parameters:

  • url (String) (defaults to: nil)

    url of page

  • version (String) (defaults to: nil)

    version of gem



21
22
23
24
# File 'lib/gem_updater/source_page_parser.rb', line 21

def initialize(url: nil, version: nil)
  @uri     = correct_uri(url)
  @version = version
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



17
18
19
# File 'lib/gem_updater/source_page_parser.rb', line 17

def uri
  @uri
end

#versionObject (readonly)

Returns the value of attribute version.



17
18
19
# File 'lib/gem_updater/source_page_parser.rb', line 17

def version
  @version
end

Instance Method Details

#changelogString?

Get the changelog in an uri.

Returns:

  • (String, nil)

    URL of changelog



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gem_updater/source_page_parser.rb', line 29

def changelog
  @changelog ||= begin
    if uri
      Bundler.ui.warn "Looking for a changelog in #{uri}"
      doc = Nokogiri::HTML(open(uri))

      find_changelog(doc)
    end

  rescue OpenURI::HTTPError # Uri points to nothing
    Bundler.ui.error "Cannot find #{uri}"
    false
  rescue Errno::ETIMEDOUT # timeout
    Bundler.ui.error "#{uri} is down"
    false
  end
end