Sha256: a11df0ec18545acafbb6ea58a07ba0d8698fff4b3e51428438fd935e4319271e

Contents?: true

Size: 1.1 KB

Versions: 18

Compression:

Stored size: 1.1 KB

Contents

module DbCharmer
  module AbstractAdapter
    module ConnectionName

      # We use this proxy to push connection name down to instrumenters w/o monkey-patching the log method itself
      class InstrumenterDecorator < ActiveSupport::BasicObject
        def initialize(adapter, instrumenter)
          @adapter = adapter
          @instrumenter = instrumenter
        end

        def instrument(name, payload = {}, &block)
          payload[:connection_name] ||= @adapter.connection_name
          @instrumenter.instrument(name, payload, &block)
        end

        def method_missing(meth, *args, &block)
          @instrumenter.send(meth, *args, &block)
        end
      end

      def self.included(base)
        base.alias_method_chain :initialize, :connection_name
      end

      def connection_name
        raise "Can't find connection configuration!" unless @config
        @config[:connection_name]
      end

      def initialize_with_connection_name(*args)
        initialize_without_connection_name(*args)
        @instrumenter = InstrumenterDecorator.new(self, @instrumenter)
      end

    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
db-charmer-1.9.1 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
db-charmer-1.9.0 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
db-charmer-1.8.4 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
db-charmer-1.8.3 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
db-charmer-1.8.2 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
db-charmer-1.8.1 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
db-charmer-1.8.0 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
db-charmer-1.8.0.pre1 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
yam-db-charmer-1.7.4.14 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
yam-db-charmer-1.7.4.13 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
yam-db-charmer-1.7.4.10 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
yam-db-charmer-1.7.4.9 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
yam-db-charmer-1.7.4.8 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
yam-db-charmer-1.7.4.0 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
yam-db-charmer-1.7.01 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
db-charmer-1.7.1 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
db-charmer-1.7.0 lib/db_charmer/rails3/abstract_adapter/connection_name.rb
db-charmer-1.7.0.pre7 lib/db_charmer/rails3/abstract_adapter/connection_name.rb