class Bundler::Changelogs::Command

Attributes

current_lockfile_parsed[RW]
previous_lockfile_parsed[RW]

Public Instance Methods

exec(_name, args) click to toggle source
# File lib/bundler/changelogs.rb, line 20
def exec(_name, args)
  if args.any?
    Bundler.require(:default, *args.map!(&:to_sym))
  else
    Bundler.require
  end

  current_lockfile = '.changelogs_gems.locked'
  previous_lockfile_content = `git show #{Bundler.settings[:changlog_commit] || "HEAD"}:#{current_lockfile}`

  self.current_lockfile_parsed = Bundler::LockfileParser.new(Bundler.read_file(current_lockfile))
  self.previous_lockfile_parsed = Bundler::LockfileParser.new(previous_lockfile_content)

  ARGV.clear
  gems = get_gems_with_changelogs
  binding.pry
  if gems.empty?
    Bundler.ui.error("Up to date. Nothing to show. Or: you already commmited the bundle changes to git? You can specify a range of git commits like this: TODO")
    return
  end

  io = StringIO.new
  write_changelog_output!(gems,io)
  io.rewind

  changelog_output_path = Bundler.settings[:changelog_output_path] 
  if changelog_output_path 
    path = Pathname.new(changelog_output_path)
    path.open("w+"){|f| f.puts io.read }

    #TODO: how to get CWD, crossplatform? Then, remove this verbosity.
    #TODO: other than error...
    Bundler.ui.info("Changelogs written to: #{path}")
  else
    Bundler.ui.info(io.read)
  end

end

Private Instance Methods

gems_excluding_bundler_plugins() click to toggle source
# File lib/bundler/changelogs.rb, line 62
def gems_excluding_bundler_plugins
  current_lockfile_parsed.dependencies.map do |token, dep|
    #TODO: next if dep is a plugin

    #don't bother showing changelogs unless it's a named gemfile AND it's an update (we shouldn't care about whole new named gems.)
    next unless previous_lockfile_parsed.dependencies[token]

    token
  end.compact
end
get_constant(name) click to toggle source
# File lib/bundler/changelogs.rb, line 102
def get_constant(name)
  Object.const_get(name)
rescue NameError
  Bundler.ui.error("Could not find constant #{name}")
  exit 1
end
get_gems_with_changelogs() click to toggle source
# File lib/bundler/changelogs.rb, line 73
def get_gems_with_changelogs
  gems = []
  for name in gems_excluding_bundler_plugins
    require name
    gem_obj = get_constant(name)
    if gem_obj[:changelog]
      #TODO: filter changelog string.
      #applicable_changelog_text = ...
      #if applicable_changelog_text.to_s.length > 0
      gems << gem_obj
      #end
    else
      Bundler.ui.error("Skipping #{name}. Found gem, but no changelog is formally specified. But you can poke around yourself: TODO, path to repo for #{name}.")
    end
  end
  gems 
rescue LoadError
  Bundler.ui.error("Skipping #{name}. Couldn't load gem and therefore could not find a changlog.")
end
write_changelog_output!(gems,io) click to toggle source
# File lib/bundler/changelogs.rb, line 93
def write_changelog_output!(gems,io)
  for gem_obj in gems
    #TODO: if gem_obj is a simpledelegate, just ask for the precomputed diff
    io.puts(gem_obj[:changelog])
  end
  nil
end