Sha256: 8ae22d6028b711c1385129594b70f3677746ffe16e588bbf5284cade995cab7a

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

class Ridgepole::ExecuteExpander
  class Stub
    def method_missing(method_name, *args, &block)
      # Nothing to do
    end
  end

  cattr_accessor :noop,     :instance_writer => false, :instance_reader => false
  cattr_accessor :callback, :instance_writer => false, :instance_reader => false

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

    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
  end # of class methods
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ridgepole-0.2.9 lib/ridgepole/execute_expander.rb
ridgepole-0.2.8 lib/ridgepole/execute_expander.rb