Class: MasonServer::CommandRunner
- Inherits:
-
Object
- Object
- MasonServer::CommandRunner
- Defined in:
- lib/mason_server/command_runner.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<<(chunk) ⇒ Object
- #file ⇒ Object
- #file_content ⇒ Object
- #file_write ⇒ Object
-
#initialize(directory, command, handler) ⇒ CommandRunner
constructor
A new instance of CommandRunner.
- #run ⇒ Object
Constructor Details
#initialize(directory, command, handler) ⇒ CommandRunner
Returns a new instance of CommandRunner.
7 8 9 10 11 |
# File 'lib/mason_server/command_runner.rb', line 7 def initialize(directory, command, handler) @directory = directory @command = command @handler = handler end |
Class Method Details
.run(directory, command, &handler) ⇒ Object
3 4 5 |
# File 'lib/mason_server/command_runner.rb', line 3 def self.run(directory, command, &handler) new(directory, command, handler).run end |
Instance Method Details
#<<(chunk) ⇒ Object
27 28 29 |
# File 'lib/mason_server/command_runner.rb', line 27 def <<(chunk) @handler.call(chunk) end |
#file ⇒ Object
40 41 42 |
# File 'lib/mason_server/command_runner.rb', line 40 def file @tmp_file ||= @directory.join("mason#{$$}"). end |
#file_content ⇒ Object
36 37 38 |
# File 'lib/mason_server/command_runner.rb', line 36 def file_content "#!/bin/sh\n#{@command}" end |
#file_write ⇒ Object
31 32 33 34 |
# File 'lib/mason_server/command_runner.rb', line 31 def file_write File.open(file, "w") { |f| f.puts file_content } file.chmod(0700) end |
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mason_server/command_runner.rb', line 13 def run file_write status = Open4.spawn( file.to_s, :dir => @directory, :out => self, :err => self, :quiet => true ) status.exitstatus end |