Sha256: ee6bca33e6041751d1710e041f8da9978270e551ae0e0876d476bc9c4dfe3e9e

Contents?: true

Size: 1003 Bytes

Versions: 1

Compression:

Stored size: 1003 Bytes

Contents

module Wherex
  module ActiveRecord
    def self.extended base
      base.class_eval do
        class << self
          alias_method_chain :establish_connection, :wherex
        end
      end
    end

    def establish_connection_with_wherex spec = nil
      establish_connection_without_wherex spec

      require 'wherex/adapters'
      ::ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, AbstractAdapter

      adapter = ::ActiveRecord::Base.connection.class
      my_adapter_name = adapter.to_s.demodulize

      begin
        my_adapter = "Wherex::#{my_adapter_name}".constantize
        adapter.send :include, my_adapter
      rescue NameError => e
      end

      if defined? ::ActiveRecord::ConnectionAdapters::SQLiteAdapter
        ::ActiveRecord::Base.connection.raw_connection.create_function( "regexp", 2 ) do |context, pattern, string|
          if string.present?
            context.result = 1 if string.match pattern
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wherex-1.0.0 lib/wherex/connection.rb