Module Footnotes::Extensions::QueryAnalyzer
In: lib/rails-footnotes/notes/queries_note.rb

Methods

Public Class methods

[Source]

# File lib/rails-footnotes/notes/queries_note.rb, line 98
      def self.included(base)
        base.class_eval do
          alias_method_chain :execute, :analyzer
        end
      end

Public Instance methods

[Source]

# File lib/rails-footnotes/notes/queries_note.rb, line 104
      def execute_with_analyzer(query, name = nil)
        query_results = nil
        time = Benchmark.realtime { query_results = execute_without_analyzer(query, name) }

        if query =~ /^(select|create|update|delete)\b/i
          type = $&.downcase.to_sym
          explain = nil

          if adapter_name == 'MySQL' && type == :select
            log_silence do
              explain = execute_without_analyzer("EXPLAIN #{query}", name)
            end
          end
          Footnotes::Notes::QueriesNote.sql << Footnotes::Extensions::Sql.new(type, name, time, query, explain)
        end

        query_results
      end

[Validate]