Class: Cumuli::CLI::Terminal

Inherits:
Object
  • Object
show all
Defined in:
lib/cumuli/cli/terminal.rb

Constant Summary collapse

VARS =
['GEM_HOME', 'GEM_PATH', 'RUBYOPT', 'RBENV_DIR']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ Terminal

Returns a new instance of Terminal.



8
9
10
# File 'lib/cumuli/cli/terminal.rb', line 8

def initialize(command)
  @command = command
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



6
7
8
# File 'lib/cumuli/cli/terminal.rb', line 6

def command
  @command
end

Instance Method Details

#bundled?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/cumuli/cli/terminal.rb', line 12

def bundled?
  Object.const_defined?('Bundler')
end

#call_bundledObject



20
21
22
23
24
25
# File 'lib/cumuli/cli/terminal.rb', line 20

def call_bundled
  Bundler.with_clean_env do
    clear_env
    execute_command
  end
end

#clear_envObject



31
32
33
# File 'lib/cumuli/cli/terminal.rb', line 31

def clear_env
  VARS.each { |e| ENV.delete(e) }
end

#execute_commandObject



27
28
29
# File 'lib/cumuli/cli/terminal.rb', line 27

def execute_command
  exec(command)
end

#spawnObject



16
17
18
# File 'lib/cumuli/cli/terminal.rb', line 16

def spawn
  bundled? ? call_bundled : execute_command
end