class Kmc::Versioner

Constants

INIT_COMMIT_MESSAGE

Public Class Methods

already_installed?(path, package) click to toggle source

Has this package already been installed?

# File lib/kmc/versioner.rb, line 41
def already_installed?(path, package)
  installed_packages(path).include?(package)
end
init_repo(path) click to toggle source
# File lib/kmc/versioner.rb, line 6
def init_repo(path)
  GitAdapter.init_repo(path)
  GitAdapter.commit_everything(path, INIT_COMMIT_MESSAGE)
end
installed_packages(path) click to toggle source
# File lib/kmc/versioner.rb, line 19
def installed_packages(path)
  commits = GitAdapter.list_commits(path)

  postinstalls = commits.select(&:post?).map(&:subject)
  uninstalls = commits.select(&:uninstall?).map(&:subject)

  # The packages that have actually been installed are those that have a
  # 'post-install' without any corresponding 'uninstall'. We can find
  # these packages by getting post-installs, and removing the first
  # instance of each package also found in uninstall.
  #
  # Note that we can't use Array#delete because that method will delete
  # *all* instances of a package, which won't work because it's possible
  # for a user to install, uninstall, then re-install a package.
  uninstalls.each do |package|
    postinstalls.delete_at(postinstalls.index(package))
  end

  postinstalls.map { |package_title| Package.find(package_title) }
end
mark_postinstall(path, package) click to toggle source
# File lib/kmc/versioner.rb, line 15
def mark_postinstall(path, package)
  GitAdapter.commit_everything(path, post_install_message(package))
end
mark_preinstall(path, package) click to toggle source
# File lib/kmc/versioner.rb, line 11
def mark_preinstall(path, package)
  GitAdapter.commit_everything(path, pre_install_message(package))
end
uninstall_package(path, package) click to toggle source
# File lib/kmc/versioner.rb, line 45
def uninstall_package(path, package)
  to_revert = GitAdapter.list_commits(path).find do |commit|
    commit.post? && commit.subject == package.title
  end

  GitAdapter.revert_commit(path, to_revert)
  Util.run_post_processors!(path)
  GitAdapter.commit_everything(path, uninstall_message(package))
end

Private Class Methods

post_install_message(package) click to toggle source
# File lib/kmc/versioner.rb, line 61
def post_install_message(package)
  "POST: #{package.title}"
end
pre_install_message(package) click to toggle source
# File lib/kmc/versioner.rb, line 57
def pre_install_message(package)
  "PRE: #{package.title}"
end
uninstall_message(package) click to toggle source
# File lib/kmc/versioner.rb, line 65
def uninstall_message(package)
  "UNINSTALL: #{package.title}"
end