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

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_env_keysObject



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

def default_env_keys
  @default_env_keys ||= []
end

.included(base) ⇒ Object



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

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

Instance Method Details

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



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

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: 86400, **kwargs).run_command }
  if defined? ::Bundler
    ::Bundler.with_clean_env { do_shellout.call }
  else
    do_shellout.call
  end
end

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



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

def shellout!(*args, **kwargs)
  if instance_of? Dapp
    default_kwarg = proc { |key, value| kwargs[key] = value unless kwargs.key?(key) }
    default_kwarg.call(:quiet, log_quiet?)
    default_kwarg.call(:time, log_time?)
  end
  _shellout_with_logging!(*args, **kwargs)
end

#shellout_cmd_should_succeed!(cmd) ⇒ Object

<< self



53
54
55
56
57
# File 'lib/dapp/dapp/shellout/base.rb', line 53

def shellout_cmd_should_succeed!(cmd)
  return cmd.tap(&:error!)
rescue ::Mixlib::ShellOut::ShellCommandFailed => e
  raise Error::Shellout, code: Helper::Trivia.class_to_lowercase(e.class), data: { stream: e.message }
end

#shellout_pack(command) ⇒ Object



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

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