Module: Spoom::Context::Bundle

Extended by:
T::Helpers
Included in:
Spoom::Context
Defined in:
lib/spoom/context/bundle.rb

Overview

Bundle features for a 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



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

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



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

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



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

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?



61
62
63
# File 'lib/spoom/context/bundle.rb', line 61

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

#gemfile_lock_specsObject

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



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

def gemfile_lock_specs
  return {} unless file?("Gemfile.lock")

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

#read_gemfileObject

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



14
15
16
# File 'lib/spoom/context/bundle.rb', line 14

def read_gemfile
  read("Gemfile")
end

#read_gemfile_lockObject

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



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

def read_gemfile_lock
  read("Gemfile.lock")
end

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

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



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

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