Sha256: a81a07d849b1ee15fdc719280aefbad723f94a7e6013b5dae6b574e05eabf2e1

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

module ActiveRecord::Turntable
  class ConnectionProxy
    module Mixable
      extend ActiveSupport::Concern

      included do
        if ActiveRecord::VERSION::STRING < '3.1'
          include Rails30
        else
          include Rails3x
        end
      end

      module Rails3x
        METHODS_REGEXP = /\A(insert|select|update|delete|exec_)/
        EXCLUDE_QUERY_REGEXP = /\A\s*SHOW/i
        QUERY_REGEXP = /\A\s*(INSERT|DELETE|UPDATE|SELECT)/i

        def mixable?(method, *args)
          (method.to_s =~ METHODS_REGEXP &&
           args.first !~ EXCLUDE_QUERY_REGEXP) ||
            (method.to_s == 'execute' && args.first =~ QUERY_REGEXP)
        end
      end

      module Rails30
        METHODS_REGEXP = /\A(insert|select|update|delete)/
        EXCLUDE_QUERY_REGEXP = /\A\s*SHOW/i
        QUERY_REGEXP = /\A\s*(INSERT|DELETE|UPDATE|SELECT)/i

        def mixable?(method, *args)
          (method.to_s =~ METHODS_REGEXP &&
           args.first !~ EXCLUDE_QUERY_REGEXP) ||
            (method.to_s == 'execute' && args.first =~ QUERY_REGEXP)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activerecord-turntable-1.1.2 lib/active_record/turntable/connection_proxy/mixable.rb
activerecord-turntable-1.1.1 lib/active_record/turntable/connection_proxy/mixable.rb
activerecord-turntable-1.1.0 lib/active_record/turntable/connection_proxy/mixable.rb
activerecord-turntable-1.0.1 lib/active_record/turntable/connection_proxy/mixable.rb
activerecord-turntable-1.0.0 lib/active_record/turntable/connection_proxy/mixable.rb