Module: Rainman::Driver::ActionMethods

Included in:
Rainman::Driver
Defined in:
lib/rainman/driver.rb

Overview

These methods are used to create handler actions.

Instance Method Summary collapse

Instance Method Details

#create_method(method, *args, &block) ⇒ Object

Private: Creates a new method.

method - The method name. args - Arguments to be supplied to the method (optional). block - Block to be supplied to the method (optional).

Examples

create_method :blah do
  # code to execute
end

Raises Rainman::AlreadyImplemented if the method already exists.

Returns a Proc.



285
286
287
288
289
290
291
# File 'lib/rainman/driver.rb', line 285

def create_method(method, *args, &block)
  if respond_to?(method, true)
    raise AlreadyImplemented, "#{inspect}::#{method}"
  else
    define_method(method, *args, &block)
  end
end

#define_action(name, opts = {}) ⇒ Object

Private: Define a new action.

name - The Symbol handler name. opts - A Hash of options used for creating the method:

:delegate_to - The method name to run on the handler. Defaults
               to the action's name.
:alias       - If supplied, an alias will be created for the
               defined method.

Example

define_action :blah

define_action :destroy, :alias => :delete

Returns a Proc.



261
262
263
264
265
266
267
268
# File 'lib/rainman/driver.rb', line 261

def define_action(name, opts = {})
  create_method(name) do |*args, &block|
    method = opts[:delegate_to] || name
    current_handler_instance.runner.send(method, *args, &block)
  end

  alias_method opts[:alias], name if opts[:alias]
end