Class: Kosmos::Versioner
- Inherits:
-
Object
- Object
- Kosmos::Versioner
- Defined in:
- lib/kosmos/versioner.rb
Constant Summary collapse
- INIT_COMMIT_MESSAGE =
"INIT: Initialize Kosmos"
Class Method Summary collapse
- .init_repo(path) ⇒ Object
- .installed_packages(path) ⇒ Object
- .mark_postinstall(path, package) ⇒ Object
- .mark_preinstall(path, package) ⇒ Object
- .uninstall_package(path, package) ⇒ Object
Class Method Details
.init_repo(path) ⇒ Object
6 7 8 9 |
# File 'lib/kosmos/versioner.rb', line 6 def init_repo(path) GitAdapter.init_repo(path) GitAdapter.commit_everything(path, INIT_COMMIT_MESSAGE) end |
.installed_packages(path) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kosmos/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 end |
.mark_postinstall(path, package) ⇒ Object
15 16 17 |
# File 'lib/kosmos/versioner.rb', line 15 def mark_postinstall(path, package) GitAdapter.commit_everything(path, (package)) end |
.mark_preinstall(path, package) ⇒ Object
11 12 13 |
# File 'lib/kosmos/versioner.rb', line 11 def mark_preinstall(path, package) GitAdapter.commit_everything(path, (package)) end |
.uninstall_package(path, package) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/kosmos/versioner.rb', line 40 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, (package)) end |