Class: Bundler::Browse::Updater

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

Instance Method Summary collapse

Constructor Details

#initializeUpdater

Returns a new instance of Updater.



10
11
12
# File 'lib/bundler/browse/updater.rb', line 10

def initialize
  @prompt = TTY::Prompt.new
end

Instance Method Details

#update_gem(gem_name) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bundler/browse/updater.rb', line 14

def update_gem(gem_name)
  puts "\n"

  confirmed = @prompt.yes?("Update #{gem_name}?")

  return unless confirmed

  puts "\nUpdating #{gem_name}..."

  command = "bundle update #{gem_name}"

  success = false
  Open3.popen2e(command) do |stdin, stdout_stderr, wait_thread|
    stdout_stderr.each_line do |line|
      puts line
    end
    success = wait_thread.value.success?
  end

  if success
    puts "\nSuccessfully updated #{gem_name}"
  else
    puts "\nFailed to update #{gem_name}"
  end

  puts "\nPress any key to continue..."
  $stdin.getch
rescue StandardError => e
  puts "\nError updating #{gem_name}: #{e.message}"
  puts "\nPress any key to continue..."
  $stdin.getch
end