Class: Ridgepole::ExecuteExpander

Inherits:
Object
  • Object
show all
Defined in:
lib/ridgepole/execute_expander.rb

Defined Under Namespace

Classes: Stub

Class Method Summary collapse

Class Method Details

.expand_execute(connection) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ridgepole/execute_expander.rb', line 23

def expand_execute(connection)
  return if connection.respond_to?(:execute_with_noop)

  class << connection
    def execute_with_noop(sql, name = nil)
      if Ridgepole::ExecuteExpander.noop
        if (callback = Ridgepole::ExecuteExpander.callback)
          callback.call(sql, name)
        end

        Stub.new
      else
        execute_without_noop(sql, name)
      end
    end
    alias_method_chain :execute, :noop
  end
end

.without_operation(callback = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/ridgepole/execute_expander.rb', line 12

def without_operation(callback = nil)
  begin
    self.noop = true
    self.callback = callback
    yield
  ensure
    self.noop = false
    self.callback = nil
  end
end