Module: RubyClock::Shell

Included in:
RubyClock
Defined in:
lib/ruby-clock/shell.rb

Instance Method Summary collapse

Instance Method Details

#shell(command) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/ruby-clock/shell.rb', line 28

def shell(command)
  case shell_runner
  when :terrapin
    Terrapin::CommandLine.new(command).run
  when :backticks
    `#{command}`
  end
end

#shell_runnerObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ruby-clock/shell.rb', line 2

def shell_runner
  @shell_runner ||= begin
    require 'terrapin'
    unless Terrapin::CommandLine.runner.class == Terrapin::CommandLine::ProcessRunner
      puts <<~MESSAGE

        🤷 terrapin is installed, but for some reason terrapin is
          using backticks as its runner.

      MESSAGE
    end

    puts '🐆 Using terrapin for shell commands.'
    :terrapin
  rescue LoadError
    puts <<~MESSAGE

      🦥 Using ruby backticks for shell commands.
         For better performance, install the terrapin gem.
         See README.md for more info.

    MESSAGE
    :backticks
  end
end