Module: Operate::Command

Extended by:
ActiveSupport::Concern
Includes:
Pubsub::Publisher
Defined in:
lib/operate/command.rb

Overview

A command-pattern implementation for controller actions, etc.

register handlers with on(). broadcast results with broadcast(). transaction wraps ActiveRecord transactions.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from Pubsub::Publisher

#broadcast, #on

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/operate/command.rb', line 35

def method_missing(method_name, *args, &block)
  if @caller.respond_to?(method_name, true)
    @caller.send(method_name, *args, &block)
  else
    super
  end
end

Instance Method Details

#evaluate(&block) ⇒ Object



30
31
32
33
# File 'lib/operate/command.rb', line 30

def evaluate(&block)
  @caller = eval('self', block.binding)
  instance_eval(&block)
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/operate/command.rb', line 43

def respond_to_missing?(method_name, include_private = false)
  @caller.respond_to?(method_name, include_private)
end

#transaction(&block) ⇒ Object



26
27
28
# File 'lib/operate/command.rb', line 26

def transaction(&block)
  ActiveRecord::Base.transaction(&block) if block_given?
end