Module: Spoom::Context::Bundle

Included in:
Spoom::Context
Defined in:
lib/spoom/context/bundle.rb

Overview

Bundle features for a context @requires_ancestor: Context

Instance Method Summary collapse

Instance Method Details

#bundle(command, version: nil, capture_err: true) ⇒ Object

Run a command with ‘bundle` in this context directory : (String command, ?version: String?, ?capture_err: bool) -> ExecResult



33
34
35
36
# File 'lib/spoom/context/bundle.rb', line 33

def bundle(command, version: nil, capture_err: true)
  command = "_#{version}_ #{command}" if version
  exec("bundle #{command}", capture_err: capture_err)
end

#bundle_exec(command, version: nil, capture_err: true) ⇒ Object

Run a command ‘bundle exec` in this context directory : (String command, ?version: String?, ?capture_err: bool) -> ExecResult



46
47
48
# File 'lib/spoom/context/bundle.rb', line 46

def bundle_exec(command, version: nil, capture_err: true)
  bundle("exec #{command}", version: version, capture_err: capture_err)
end

#bundle_install!(version: nil, capture_err: true) ⇒ Object

Run ‘bundle install` in this context directory : (?version: String?, ?capture_err: bool) -> ExecResult



40
41
42
# File 'lib/spoom/context/bundle.rb', line 40

def bundle_install!(version: nil, capture_err: true)
  bundle("install", version: version, capture_err: capture_err)
end

#gem_version_from_gemfile_lock(gem) ⇒ Object

Get ‘gem` version from the `Gemfile.lock` content

Returns ‘nil` if `gem` cannot be found in the Gemfile. : (String gem) -> Gem::Version?



63
64
65
# File 'lib/spoom/context/bundle.rb', line 63

def gem_version_from_gemfile_lock(gem)
  gemfile_lock_specs[gem]&.version
end

#gemfile_lock_specsObject

: -> Hash[String, Bundler::LazySpecification]



51
52
53
54
55
56
57
# File 'lib/spoom/context/bundle.rb', line 51

def gemfile_lock_specs
  lockfile = read_gemfile_lock
  return {} unless lockfile

  parser = Bundler::LockfileParser.new(lockfile)
  parser.specs.to_h { |spec| [spec.name, spec] }
end

#read_gemfileObject

Read the contents of the Gemfile in this context directory : -> String?



11
12
13
14
15
# File 'lib/spoom/context/bundle.rb', line 11

def read_gemfile
  read("Gemfile")
rescue Errno::ENOENT, Errno::EACCES
  nil
end

#read_gemfile_lockObject

Read the contents of the Gemfile.lock in this context directory : -> String?



19
20
21
22
23
# File 'lib/spoom/context/bundle.rb', line 19

def read_gemfile_lock
  read("Gemfile.lock")
rescue Errno::ENOENT, Errno::EACCES
  nil
end

#write_gemfile!(contents, append: false) ⇒ Object

Set the ‘contents` of the Gemfile in this context directory : (String contents, ?append: bool) -> void



27
28
29
# File 'lib/spoom/context/bundle.rb', line 27

def write_gemfile!(contents, append: false)
  write!("Gemfile", contents, append: append)
end