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