Class: Rectify::Command

Inherits:
Object
  • Object
show all
Includes:
Wisper::Publisher
Defined in:
lib/rectify/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



20
21
22
23
24
25
26
# File 'lib/rectify/command.rb', line 20

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

Class Method Details

.call(*args, &block) ⇒ Object



5
6
7
8
9
# File 'lib/rectify/command.rb', line 5

def self.call(*args, &block)
  command = new(*args)
  command.evaluate(&block) if block_given?
  command.call
end

Instance Method Details

#evaluate(&block) ⇒ Object



11
12
13
14
# File 'lib/rectify/command.rb', line 11

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

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

Returns:

  • (Boolean)


28
29
30
# File 'lib/rectify/command.rb', line 28

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

#transaction(&block) ⇒ Object



16
17
18
# File 'lib/rectify/command.rb', line 16

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