Sha256: 4002ee85320776fce3d13cd943c7dcf493e96229c93dec54da16aacddf8a2347

Contents?: true

Size: 1008 Bytes

Versions: 1

Compression:

Stored size: 1008 Bytes

Contents

module Octoshark
  module ActiveRecordBase
    extend ActiveSupport::Concern

    included do
      class << self
        alias_method_chain :establish_connection, :octoshark
      end
    end

    module ClassMethods
      def establish_connection_with_octoshark(*args)
        establish_connection_without_octoshark(*args)
        Octoshark.reload! if Octoshark.configured?
      end
    end
  end

  module ActiveRecordLogSubscriber
    extend ActiveSupport::Concern

    included do
      alias_method_chain :debug, :octoshark
    end

    def debug_with_octoshark(msg)
      prefix = if Octoshark.current_connection_name.present?
                 color("[Octoshark: #{Octoshark.current_connection_name}]",
                       ActiveSupport::LogSubscriber::GREEN, true)
               end
      debug_without_octoshark("#{prefix}#{msg}")
    end
  end
end

ActiveRecord::Base.send(:include, Octoshark::ActiveRecordBase)
ActiveRecord::LogSubscriber.send(:include, Octoshark::ActiveRecordLogSubscriber)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
octoshark-0.0.4 lib/octoshark/active_record_extensions.rb