Class: Bundler::Whatsup::ChangelogFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/whatsup/changelog_fetcher.rb

Overview

Fetches changelog file for given gem name

Examples:

changelog_content = ChangelogFetcher.load('sinatra').content
has_changelog     = ChangelogFetcher.load('rais').changelog?

Constant Summary collapse

CHANGELOG_NAME_REGEXP =
/(?<ch_name>changelog|changes).?(md|txt)?/i
GITHUB_REPO_REGEXP =
%r{(https|http)://github.com/(?<gem_repo_name>[\S]+/[\S]+)}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gem_info) ⇒ ChangelogFetcher

Returns a new instance of ChangelogFetcher.


20
21
22
23
# File 'lib/bundler/whatsup/changelog_fetcher.rb', line 20

def initialize(gem_info)
  @url = gem_info.values_at('source_code_uri', 'homepage_uri').compact.grep(GITHUB_REPO_REGEXP).first
  load_changelog
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content


15
16
17
# File 'lib/bundler/whatsup/changelog_fetcher.rb', line 15

def content
  @content
end

Class Method Details

.load(gem_name) ⇒ ChangelogFetcher

Creates and setups Changelog::Fetcher object for given gem name

Examples:

Changelog::Fetcher.load('nokogiri')

Parameters:

  • gem_name (String)

    Name of the gem

Returns:

Raises:

  • (ArgumentError)

33
34
35
36
37
# File 'lib/bundler/whatsup/changelog_fetcher.rb', line 33

def load(gem_name)
  gem_info = Gems.info(gem_name.downcase)
  raise ArgumentError, "Gem #{gem_name} not found" if gem_info.empty?
  new(gem_info)
end

Instance Method Details

#changelog?Boolean

Checks if gem has changelog file or not

Returns:

  • (Boolean)

44
45
46
# File 'lib/bundler/whatsup/changelog_fetcher.rb', line 44

def changelog?
  !@content.nil?
end

#filenameString|nil

Resolves changelog filename

Returns:

  • (String|nil)

51
52
53
# File 'lib/bundler/whatsup/changelog_fetcher.rb', line 51

def filename
  @filename ||= resolve_filename
end

#repo_nameString

Calculates gem repository name and its owner name at Github based on urls presented in gem metadata

Returns:

  • (String)

58
59
60
61
# File 'lib/bundler/whatsup/changelog_fetcher.rb', line 58

def repo_name
  return unless @url
  @repo_name ||= Octokit::Repository.from_url(@url).to_s.chomp('.git')
end