lib/vedeu/distributed/subprocess.rb in vedeu-0.6.8 vs lib/vedeu/distributed/subprocess.rb in vedeu-0.6.9

- old
+ new

@@ -1,96 +1,100 @@ module Vedeu - # @example - # Vedeu::TestApplication.build - # - class Subprocess + module Distributed - # @param (see #initialize) - def self.execute!(application) - new(application).execute! - end - - # Returns a new instance of Vedeu::Subprocess. + # @example + # Vedeu::TestApplication.build # - # @param application [Vedeu::TestApplication] - # @return [Vedeu::Subprocess] - def initialize(application) - @application = application - @pid = nil - end + class Subprocess - # :nocov: - # @return [Array] - def execute! - file_open && file_write && file_close + # @param (see #initialize) + def self.execute!(application) + new(application).execute! + end - @pid = fork do - exec(file_path) + # Returns a new instance of Vedeu::Distributed::Subprocess. + # + # @param application [Vedeu::TestApplication] + # @return [Vedeu::Distributed::Subprocess] + def initialize(application) + @application = application + @pid = nil end - Process.detach(@pid) + # :nocov: + # @return [Array] + def execute! + file_open && file_write && file_close - self - end - # :nocov: + @pid = fork do + exec(file_path) + end - # Sends the KILL signal to the process. - # - # @return [void] - def kill - Process.kill('KILL', pid) + Process.detach(@pid) - file_unlink - end + self + end + # :nocov: - protected + # Sends the KILL signal to the process. + # + # @return [void] + def kill + Process.kill('KILL', pid) - # @!attribute [r] application - # @return [Vedeu::TestApplication] - attr_reader :application + file_unlink + end - # @!attribute [r] pid - # @return [Fixnum] - attr_reader :pid + protected - private + # @!attribute [r] application + # @return [Vedeu::TestApplication] + attr_reader :application - # @return [String] - def command - "ruby #{file_path}" - end + # @!attribute [r] pid + # @return [Fixnum] + attr_reader :pid - # @return [Fixnum] The number of bytes written. - def file_write - file.write(application) - end + private - # @return [NilClass] - def file_close - file.close - end + # @return [String] + def command + "ruby #{file_path}" + end - # @return [Fixnum] The number of files removed; 1. - def file_unlink - File.unlink("/tmp/foo_#{timestamp}") - end + # @return [Fixnum] The number of bytes written. + def file_write + file.write(application) + end - # return [String] - def file_path - file.path - end + # @return [NilClass] + def file_close + file.close + end - # @return [File] - def file_open - @file ||= File.new("/tmp/foo_#{timestamp}", 'w', 0755) - end - alias_method :file, :file_open + # @return [Fixnum] The number of files removed; 1. + def file_unlink + File.unlink("/tmp/foo_#{timestamp}") + end - # return [Fixnum] - def timestamp - @timestamp ||= Time.now.to_i - end + # return [String] + def file_path + file.path + end - end # Subprocess + # @return [File] + def file_open + @file ||= File.new("/tmp/foo_#{timestamp}", 'w', 0755) + end + alias_method :file, :file_open + + # return [Fixnum] + def timestamp + @timestamp ||= Time.now.to_i + end + + end # Subprocess + + end # Distributed end # Vedeu