Module: Runnable::ClassMethods
- Defined in:
- lib/runnable.rb
Accessors for the module class variables collapse
-
#commands ⇒ Hash
Returns the user defined commands.
-
#processes ⇒ Hash
Returns the list of runnable instances by pid.
-
#processes=(value) ⇒ Object
Processes writer.
Instance Method Summary collapse
-
#command_style(style) ⇒ nil
Define the parameter style to be used.
-
#define_command(name, opts = {}, &block) ⇒ nil
Create a user definde command.
-
#executes(cmd) ⇒ nil
Define the command to be executed.
-
#method_missing(name, *opts) ⇒ Object
Method missing processing for the command processors.
-
#processors(opts = nil) ⇒ Object
Generic command processor.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *opts) ⇒ Object
Method missing processing for the command processors
92 93 94 95 96 97 98 99 100 |
# 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 |
Instance Method Details
#command_style(style) ⇒ nil
Define the parameter style to be used.
52 53 54 |
# File 'lib/runnable.rb', line 52 def command_style( style ) define_method( :command_style ) { style } end |
#commands ⇒ Hash
Returns the user defined commands
106 107 108 |
# File 'lib/runnable.rb', line 106 def commands @commands ||= Hash.new end |
#define_command(name, opts = {}, &block) ⇒ nil
Create a user definde command
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# 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 |
#executes(cmd) ⇒ nil
Define the command to be executed
46 47 48 |
# File 'lib/runnable.rb', line 46 def executes( cmd ) define_method( :command ) { cmd } end |
#processes ⇒ Hash
Returns the list of runnable instances by pid
112 113 114 |
# File 'lib/runnable.rb', line 112 def processes @processes ||= Hash.new end |
#processes=(value) ⇒ Object
Processes writer
117 118 119 |
# File 'lib/runnable.rb', line 117 def processes=( value ) @processes = value end |
#processors(opts = nil) ⇒ Object
Generic command processor. It allows to define generic processors used in all the user defined commands
83 84 85 86 87 88 89 |
# File 'lib/runnable.rb', line 83 def processors( opts = nil ) if opts.is_a? Hash @processors = opts else @processors ||= Hash.new end end |