Class: Hanami::CLI::Bundler
- Inherits:
-
Object
- Object
- Hanami::CLI::Bundler
- Defined in:
- lib/hanami/cli/bundler.rb
Overview
Conveniences for running bundler
from CLI commands.
Class Method Summary collapse
-
.require(*groups) ⇒ void
If a
Gemfile
exists, sets up the Bundler environment and loads all the gems from the given groups.
Instance Method Summary collapse
-
#bundle(cmd, env: nil, &block) ⇒ Object
Executes the given command prefixed by
bundle
. -
#exec(cmd, env: nil, &blk) ⇒ SystemCall::Result
Executes the given command prefixed by
bundle exec
. -
#hanami_exec(cmd, env: nil, &blk) ⇒ SystemCall::Result
Runs the given Hanami CLI command via
bundle exec hanami
. -
#initialize(fs: Hanami::CLI::Files.new, system_call: SystemCall.new) ⇒ Bundler
constructor
Returns a new bundler.
-
#install ⇒ SystemCall::Result
Runs
bundle install
for the Hanami app. -
#install! ⇒ SystemCall::Result
Runs
bundle install
for the Hanami app and raises an error if the command does not execute successfully.
Constructor Details
Class Method Details
.require(*groups) ⇒ void
This method returns an undefined value.
If a Gemfile
exists, sets up the Bundler environment and loads all the gems from the given
groups.
This can be called multiple times with different groups.
This is a convenience wrapper for Bundler.require
.
40 41 42 43 44 |
# File 'lib/hanami/cli/bundler.rb', line 40 def self.require(*groups) return unless File.exist?(ENV.fetch(BUNDLE_GEMFILE) { DEFAULT_GEMFILE_PATH }) ::Bundler.require(*groups) end |
Instance Method Details
#bundle(cmd, env: nil) ⇒ Object #bundle(cmd, env: nil, &blk) ⇒ Object
Executes the given command prefixed by bundle
.
This is how you should execute all bundle subcommands.
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/hanami/cli/bundler.rb', line 131 def bundle(cmd, env: nil, &block) bundle_bin = which("bundle") hanami_env = "HANAMI_ENV=#{env} " unless env.nil? system_call.call( "#{hanami_env}#{bundle_bin} #{cmd}", env: {BUNDLE_GEMFILE => fs.(DEFAULT_GEMFILE_PATH)}, &block ) end |
#exec(cmd, env: nil, &blk) ⇒ SystemCall::Result
Executes the given command prefixed by bundle exec
.
104 105 106 |
# File 'lib/hanami/cli/bundler.rb', line 104 def exec(cmd, env: nil, &blk) bundle("exec #{cmd}", env: env, &blk) end |
#hanami_exec(cmd, env: nil, &blk) ⇒ SystemCall::Result
Runs the given Hanami CLI command via bundle exec hanami
92 93 94 95 96 |
# File 'lib/hanami/cli/bundler.rb', line 92 def hanami_exec(cmd, env: nil, &blk) exec("hanami #{cmd}", env: env, &blk).tap do |result| raise HanamiExecError.new(cmd, result.err) unless result.successful? end end |
#install ⇒ SystemCall::Result
Runs bundle install
for the Hanami app.
64 65 66 67 |
# File 'lib/hanami/cli/bundler.rb', line 64 def install parallelism_level = Etc.nprocessors bundle "install --jobs=#{parallelism_level} --quiet --no-color" end |
#install! ⇒ SystemCall::Result
Runs bundle install
for the Hanami app and raises an error if the command does not execute
successfully.
78 79 80 81 82 |
# File 'lib/hanami/cli/bundler.rb', line 78 def install! install.tap do |result| raise BundleInstallError.new(result.err) unless result.successful? end end |