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



44
45
46
47
48
49
50
# File 'lib/rectify/command.rb', line 44

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



24
25
26
27
28
29
30
31
32
33
# File 'lib/rectify/command.rb', line 24

def self.call(*args, &block)
  event_recorder = EventRecorder.new

  command = new(*args)
  command.subscribe(event_recorder)
  command.evaluate(&block) if block_given?
  command.call

  event_recorder.events
end

Instance Method Details

#evaluate(&block) ⇒ Object



35
36
37
38
# File 'lib/rectify/command.rb', line 35

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

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

Returns:

  • (Boolean)


52
53
54
# File 'lib/rectify/command.rb', line 52

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

#transaction(&block) ⇒ Object



40
41
42
# File 'lib/rectify/command.rb', line 40

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