Module: Dapp::Project::Shellout::Base

Includes:
Streaming
Included in:
Dapp::Project
Defined in:
lib/dapp/project/shellout/base.rb

Overview

Base

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_env_keysObject



47
48
49
# File 'lib/dapp/project/shellout/base.rb', line 47

def default_env_keys
  @default_env_keys ||= []
end

.included(base) ⇒ Object



43
44
45
# File 'lib/dapp/project/shellout/base.rb', line 43

def included(base)
  base.extend(self)
end

Instance Method Details

#shellout(*args, **kwargs) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dapp/project/shellout/base.rb', line 9

def shellout(*args, **kwargs)
  env = nil

  Base.default_env_keys.each do |env_key|
    env_key = env_key.to_s.upcase
    env ||= {}
    env[env_key] = ENV[env_key]
  end

  param_env = (kwargs.delete(:env) || kwargs.delete(:environment))
  param_env = param_env.map { |key, value| [key.to_s.upcase, value.to_s] }.to_h if param_env

  env = (env || {}).merge(param_env) if param_env
  kwargs[:env] = env if env

  do_shellout = -> { ::Mixlib::ShellOut.new(*args, timeout: 3600, **kwargs).run_command }
  if defined? ::Bundler
    ::Bundler.with_clean_env { do_shellout.call }
  else
    do_shellout.call
  end
end

#shellout!(*args, **kwargs) ⇒ Object



32
33
34
35
36
# File 'lib/dapp/project/shellout/base.rb', line 32

def shellout!(*args, **kwargs)
  shellout_with_logging(**kwargs) do |options|
    shellout(*args, **options).tap(&:error!)
  end
end

#shellout_pack(command) ⇒ Object



38
39
40
# File 'lib/dapp/project/shellout/base.rb', line 38

def shellout_pack(command)
  "eval $(#{echo_path} #{Base64.strict_encode64(command)} | base64 --decode)"
end