Class: CreateRubyGem::Detection::BundlerVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/create_ruby_gem/detection/bundler_version.rb

Overview

Detects the installed Bundler version by running bundle –version.

Constant Summary collapse

VERSION_PATTERN =
/(\d+\.\d+\.\d+)/

Instance Method Summary collapse

Constructor Details

#initialize(bundle_command: 'bundle') ⇒ BundlerVersion



11
12
13
# File 'lib/create_ruby_gem/detection/bundler_version.rb', line 11

def initialize(bundle_command: 'bundle')
  @bundle_command = bundle_command
end

Instance Method Details

#detect!Gem::Version

Runs bundle –version and parses the result.

Raises:



20
21
22
23
24
25
26
27
28
# File 'lib/create_ruby_gem/detection/bundler_version.rb', line 20

def detect!
  output = IO.popen([@bundle_command, '--version'], err: i[child out], &:read)
  version = output[VERSION_PATTERN, 1]
  return Gem::Version.new(version) if version

  raise UnsupportedBundlerVersionError, "Cannot parse bundler version from: #{output.inspect}"
rescue Errno::ENOENT
  raise UnsupportedBundlerVersionError, "Bundler executable not found: #{@bundle_command}"
end