Class: SafeUpdate::Updater

Inherits:
Object
  • Object
show all
Defined in:
lib/safe_update/updater.rb

Instance Method Summary collapse

Constructor Details

#initialize(git_repo = nil) ⇒ Updater

Returns a new instance of Updater.



3
4
5
6
# File 'lib/safe_update/updater.rb', line 3

def initialize(git_repo = nil)
  @git_repo = git_repo || GitRepo.new
  @git_repo.perform_safety_checks
end

Instance Method Details

#run(push: nil, test_command: nil) ⇒ Object

push:

If push is eg. 3, we will run @git_repo.push every 3 commits.
If push is nil, we will never run git push.

test_command:

Command to run your tests after each gem update.
If exit status is non-zero, the gem will not be updated.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/safe_update/updater.rb', line 13

def run(push: nil, test_command: nil)
  run_git_push = (push && push.to_i > 0) ? true : false
  push_interval = push.to_i if run_git_push

  puts 'Finding outdated gems...'
  outdated_gems = get_outdated_gems

  presenter = SafeUpdate::Presenter.new
  Thread.new { presenter.call(outdated_gems) }

  outdated_gems.to_enum.with_index(1) do |outdated_gem, index|
    outdated_gem.attempt_update(test_command)
    @git_repo.push if run_git_push && index % push_interval == 0
  end

  # run it once at the very end, so the final commit can be tested in CI
  @git_repo.push if run_git_push

  presenter.stop
end