Class: BundleUpdateInteractive::GitCommitter

Inherits:
Object
  • Object
show all
Defined in:
lib/bundle_update_interactive/git_committer.rb

Instance Method Summary collapse

Constructor Details

#initialize(updater) ⇒ GitCommitter

Returns a new instance of GitCommitter.



7
8
9
# File 'lib/bundle_update_interactive/git_committer.rb', line 7

def initialize(updater)
  @updater = updater
end

Instance Method Details

#apply_updates_as_individual_commits(*gem_names) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bundle_update_interactive/git_committer.rb', line 11

def apply_updates_as_individual_commits(*gem_names)
  assert_git_executable!
  assert_working_directory_clean!

  gem_names.flatten.each do |name|
    updates = updater.apply_updates(name)
    updated_gem = updates[name] || updates.values.first
    next if updated_gem.nil?

    commit_message = format_commit_message(updated_gem)
    system "git add Gemfile Gemfile.lock", exception: true
    system "git commit -m #{commit_message.shellescape}", exception: true
  end
end

#format_commit_message(outdated_gem) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bundle_update_interactive/git_committer.rb', line 26

def format_commit_message(outdated_gem)
  [
    "Update",
    outdated_gem.name,
    outdated_gem.current_version.to_s,
    outdated_gem.current_git_version,
    "",
    outdated_gem.updated_version.to_s,
    outdated_gem.updated_git_version
  ].compact.join(" ")
end