class WhatTheGem::Changes

Constants

BundledSince
CHANGELOG_NOT_FOUND
GlobalSince
SinceFirst
TEMPLATE
VERSION_LINE_REGEXP
VERSION_REGEXP

Public Instance Methods

locals() click to toggle source
# File lib/whatthegem/changes.rb, line 50
def locals
  {
    since: since.to_h,
    versions: select_versions.reverse.map(&:to_h)
  }
end

Private Instance Methods

best_changelog(*changelogs) click to toggle source
# File lib/whatthegem/changes.rb, line 102
def best_changelog(*changelogs)
  # in case they have both (releases & CHANGELOG.md)...
  list = changelogs.compact.reject(&:empty?)
  return list.first if list.size < 2

  # Some gems have "old" changelog in file, and new in releases, or vice versa
  if list.map { |*, last| last.number }.uniq.one?
    # If both have the same latest version, return one having more text
    list.max_by { |*, last| last.body.size }
  else
    # Return newer, if one of them are
    list.max_by { |*, last| last.number }
  end
end
bundled_since() click to toggle source
# File lib/whatthegem/changes.rb, line 80
def bundled_since
  return unless gem.bundled.present?
  gem.bundled.spec.version.then(&BundledSince.method(:new))
end
global_since() click to toggle source
# File lib/whatthegem/changes.rb, line 85
def global_since
  gem.specs.first&.version&.then(&GlobalSince.method(:new))
end
output() click to toggle source
Calls superclass method
# File lib/whatthegem/changes.rb, line 59
def output
  return CHANGELOG_NOT_FOUND unless versions
  markdown super
end
select_versions() click to toggle source
# File lib/whatthegem/changes.rb, line 69
def select_versions
  return [] unless versions&.any?
  res = versions.select { |v| v.number > since.version }
  res = versions if res.empty? # if we are at the last version, show all historical changes

  # TODO: If there are a lot of versions, we can do "intellectual selection", like
  # two last minor + last major or something

  res
end
since() click to toggle source

TODO: allow to pass `since` as a parameter

# File lib/whatthegem/changes.rb, line 65
def since
  bundled_since || global_since || SinceFirst.new(versions.first.number)
end
versions() click to toggle source
# File lib/whatthegem/changes.rb, line 89
        def versions
  best_changelog(versions_from_releases, versions_from_file)
end
versions_from_file() click to toggle source
# File lib/whatthegem/changes.rb, line 97
def versions_from_file
  # always take the freshest from GitHub, even when installed locally
  gem.github&.changelog&.then(&Parser)
end
versions_from_releases() click to toggle source
# File lib/whatthegem/changes.rb, line 93
def versions_from_releases
  gem.github&.releases&.then(&ReleasesParser)
end