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



29
30
31
32
# File 'lib/spoom/context/bundle.rb', line 29

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



42
43
44
# File 'lib/spoom/context/bundle.rb', line 42

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



36
37
38
# File 'lib/spoom/context/bundle.rb', line 36

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?



58
59
60
# File 'lib/spoom/context/bundle.rb', line 58

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

#gemfile_lock_specsObject

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



47
48
49
50
51
52
# File 'lib/spoom/context/bundle.rb', line 47

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?



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

def read_gemfile
  read("Gemfile")
end

#read_gemfile_lockObject

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



17
18
19
# File 'lib/spoom/context/bundle.rb', line 17

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



23
24
25
# File 'lib/spoom/context/bundle.rb', line 23

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