Module: Wherex::ActiveRecord

Defined in:
lib/wherex/connection.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/wherex/connection.rb', line 3

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

Instance Method Details

#establish_connection_with_wherex(spec = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/wherex/connection.rb', line 11

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 ::ActiveRecord::Base.connection.raw_connection.respond_to? :create_function
    ::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