module Runnable::ClassMethods
Public Instance Methods
Define the parameter style to be used. @return [nil]
# File lib/runnable.rb, line 52 def command_style( style ) define_method( :command_style ) { style } end
Returns the user defined commands @return [Hash] commands User defined commands
# File lib/runnable.rb, line 106 def commands @commands ||= Hash.new end
Create a user definde command @return [nil] @param [Symbol] name The user defined command name @param [Hash] options Options. @option options :blocking (false) Describe if the execution is blocking or non-blocking @option options :log_path (false) Path used to store logs # (dont store logs if no path specified)
# File lib/runnable.rb, line 62 def define_command( name, opts = {}, &block ) blocking = opts[:blocking] || false log_path = opts[:log_path] || false commands[name] = { :blocking => blocking } define_method( name ) do |*args| if block run name, block.call(*args), log_path else run name, nil, log_path end join if blocking end end
Define the command to be executed @return [nil] @param [Symbol] command Command to be executed
# File lib/runnable.rb, line 46 def executes( cmd ) define_method( :command ) { cmd } end
Method missing processing for the command processors
# File lib/runnable.rb, line 92 def method_missing( name, *opts ) raise NoMethodError.new( name.to_s ) unless name.to_s =~ /([a-z]*)_([a-z]*)/ # command_processors if $2 == "processors" commands[$1.to_sym][:outputs] = opts.first[:outputs] commands[$1.to_sym][:exceptions] = opts.first[:exceptions] end end
Returns the list of runnable instances by pid @return [Hash] list of runnable instances by pid
# File lib/runnable.rb, line 112 def processes @processes ||= Hash.new end
Processes writer
# File lib/runnable.rb, line 117 def processes=( value ) @processes = value end
Generic command processor. It allows to define generic processors used in all the user defined commands @param [Hash] opts Processing options @option opts :outputs (nil) Output processing Hash (regexp => output) @option opts :exceptions (nil) Exceptions processing Hash (regexp => exception)
# File lib/runnable.rb, line 83 def processors( opts = nil ) if opts.is_a? Hash @processors = opts else @processors ||= Hash.new end end