Module: ActiveRecord::Comments::ExecuteWithComments

Defined in:
lib/active_record/comments.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_record/comments.rb', line 7

def included(base)
  base.class_eval do
    # ActiveRecord 3.2 vs sqlite, maybe others ...
    if base.method_defined?(:exec_query)
      alias_method :exec_query_without_comment, :exec_query
      def exec_query(query, *args, &block)
        query = ActiveRecord::Comments.with_comment_sql(query)
        exec_query_without_comment(query, *args, &block)
      end

    # 99% case
    elsif base.method_defined?(:execute)
      alias_method :execute_without_comment, :execute
      def execute(query, *args, &block)
        query = ActiveRecord::Comments.with_comment_sql(query)
        execute_without_comment(query, *args, &block)
      end
    end
  end
end

.install!Object


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/active_record/comments.rb', line 28

def install!
  if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
    install ActiveRecord::ConnectionAdapters::SQLite3Adapter
  end

  if defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
    install ActiveRecord::ConnectionAdapters::MysqlAdapter
  end

  if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
    install ActiveRecord::ConnectionAdapters::Mysql2Adapter
  end

  if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
    install ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
  end
end