lib/runnable.rb in runnable-0.1.2 vs lib/runnable.rb in runnable-0.2.0
- old
+ new
@@ -17,12 +17,10 @@
require 'runnable/gnu'
require 'runnable/extended'
-require 'publisher'
-
# Convert a executable command in a Ruby-like class
# you are able to start, define params and send signals (like kill, or stop)
#
# @example Usage:
# class LS < Runnable
@@ -30,16 +28,11 @@
# end
#
# ls = LS.new
# ls.alh
# ls.run
-class Runnable
- extend Publisher
-
- # Fires to know whats happening inside
- can_fire :fail, :finish
-
+class Runnable
# Process id.
attr_reader :pid
# Process owner.
attr_reader :owner
# Process group.
@@ -125,12 +118,10 @@
create_log_directory
end
# Start the execution of the command.
# @return [nil]
- # @fire :finish
- # @fire :fail
def run
# Create a new mutex
@pid_mutex = Mutex.new
# Create pipes to redirect Standar I/O
@@ -170,15 +161,15 @@
exit_status = $?.exitstatus
# In case of error add an Exception to the @excep_array
@excep_array << SystemCallError.new( exit_status ) if exit_status != 0
- # Fire signals according to the exit code
+ # Call methods according to the exit code
if @excep_array.empty?
- fire :finish
+ finish
else
- fire :fail, @excep_array
+ failed( @excep_array )
end
# This instance is finished and we remove it
@@processes.delete( @pid )
end
@@ -341,9 +332,24 @@
# be raised as values.
def exceptions
{}
end
+ # @abstract
+ # Method called when command ends with no erros.
+ # This method is a hook so it should be overwritten in child classes.
+ # @return [nil]
+ def finish
+ end
+
+ # @abstract
+ # Method called when command executions fail.
+ # This method is a hook so it should be overwritten in child classes.
+ # @param [Array] exceptions Array containing exceptions raised during the command execution.
+ # @return [nil]
+ def failed( exceptions )
+ end
+
protected
# Send the desired signal to the command.
# @param [Symbol] Signal to be send to the command.
# @todo raise ESRCH if pid is not in system