Class: Bunup::Bundler

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

Overview

Run bundler commands

Constant Summary collapse

OUTDATED_PATTERN =

Expects:

"rails (newest 5.2.1, installed 5.2.0)"
or
"rails (newest 5.2.1, installed 5.2.0, requested = 5.2.0)"
/
  (?<name>.*)\s
  \(newest\s(?<newest>.*),\s
  installed\s(?<installed>.*?)
  (?:,\srequested.*)?
  \)
/x.freeze

Class Method Summary collapse

Class Method Details

.outdated(gem_names, only_explicit: false) ⇒ Object

Expected output format:

"\ngem-name (newest 1.0.0, installed 2.0.0)\n"


22
23
24
25
26
27
28
29
30
# File 'lib/bunup/bundler.rb', line 22

def self.outdated(gem_names, only_explicit: false)
  args = %w[--parseable --strict]
  args << '--only-explicit' if only_explicit
  stdout, stderr, status = Open3.capture3(
    "bundler outdated #{gem_names.join(' ')} #{args.join(' ')}"
  )
  validate_output(stdout, stderr, status)
  stdout.strip
end

.validate_output(stdout, stderr, status) ⇒ Object

Raises:

  • (::SystemExit)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bunup/bundler.rb', line 32

def self.validate_output(stdout, stderr, status)
  # `bundler outdated` exits with a 0 status if the gem is up-to-date
  raise ::SystemExit.new(true, 'Gem is up-to-date') if status.success?

  # `bundler outdated` exits with a status of 256 if the gem is out-of-date.
  # If it exits with some other status, print the error and exit with that
  # status
  unless status.to_i == 256
    raise ::SystemExit.new(
      status.to_i,
      "#{(stderr == '' ? stdout : stderr).chomp}\n"
    )
  end
end