Class: Lexicon::Common::ShellExecutor
- Inherits:
-
Object
- Object
- Lexicon::Common::ShellExecutor
- Includes:
- Mixin::Finalizable
- Defined in:
- lib/lexicon/common/shell_executor.rb
Instance Method Summary collapse
- #execute(command) ⇒ String
- #finalize ⇒ Object
-
#initialize ⇒ ShellExecutor
constructor
A new instance of ShellExecutor.
Methods included from Mixin::Finalizable
Constructor Details
#initialize ⇒ ShellExecutor
Returns a new instance of ShellExecutor.
8 9 10 |
# File 'lib/lexicon/common/shell_executor.rb', line 8 def initialize @command_dir = Dir.mktmpdir end |
Instance Method Details
#execute(command) ⇒ String
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lexicon/common/shell_executor.rb', line 14 def execute(command) cmd = Tempfile.new('command-', @command_dir) cmd.write <<~BASH #!/usr/bin/env bash set -e #{command} BASH cmd.close `bash #{cmd.path}` ensure cmd.close cmd.unlink end |
#finalize ⇒ Object
30 31 32 33 34 |
# File 'lib/lexicon/common/shell_executor.rb', line 30 def finalize if !@command_dir.nil? FileUtils.rm_rf(@command_dir) end end |