Module: Runnable::ClassMethods

Defined in:
lib/runnable.rb

Accessors for the module class variables collapse

Instance Method Summary collapse

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

Raises:

  • (NoMethodError)


88
89
90
91
92
93
94
95
96
# File 'lib/runnable.rb', line 88

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

#commandsHash

Returns the user defined commands



102
103
104
# File 'lib/runnable.rb', line 102

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
# 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|
    run name, block.call(*args), log_path
    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

#processesHash

Returns the list of runnable instances by pid



108
109
110
# File 'lib/runnable.rb', line 108

def processes
  @processes ||= Hash.new
end

#processes=(value) ⇒ Object

Processes writer



113
114
115
# File 'lib/runnable.rb', line 113

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

Options Hash (opts):

  • :outputs (Object) — default: nil

    Output processing Hash (regexp => output)

  • :exceptions (Object) — default: nil

    Exceptions processing Hash (regexp => exception)



79
80
81
82
83
84
85
# File 'lib/runnable.rb', line 79

def processors( opts = nil )
  if opts.is_a? Hash
    @processors = opts
  else
    @processors ||= Hash.new
  end
end