Class Footnotes::Notes::QueriesNote
In: lib/rails-footnotes/notes/queries_note.rb
Parent: AbstractNote

Methods

Public Class methods

[Source]

# File lib/rails-footnotes/notes/queries_note.rb, line 9
      def self.start!(controller)
        @@sql = []
      end

[Source]

# File lib/rails-footnotes/notes/queries_note.rb, line 13
      def self.to_sym
        :queries
      end

Public Instance methods

[Source]

# File lib/rails-footnotes/notes/queries_note.rb, line 31
      def content
        html = ''

        @@sql.each_with_index do |item, i|
          sql_links = []
          sql_links << "<a href=\"#\" style=\"color:#A00;\" onclick=\"Footnotes.toggle('qtable_#{i}');return false\">explain</a>" if item.explain
          sql_links << "<a href=\"#\" style=\"color:#00A;\" onclick=\"Footnotes.toggle('qtrace_#{i}');return false\">trace</a>" if item.trace

html << "<b id=\"qtitle_\#{i}\">\#{escape(item.type.to_s.upcase)}</b> (\#{sql_links.join(' | ')})<br />\n\#{print_name_and_time(item.name, item.time)}<br />\n\#{print_query(item.query)}<br />\n\#{print_explain(i, item.explain) if item.explain}\n<p id=\"qtrace_\#{i}\" style=\"display:none;\">\#{parse_trace(item.trace) if item.trace}</p><br />\n"
        end

        return html
      end

[Source]

# File lib/rails-footnotes/notes/queries_note.rb, line 21
      def stylesheet
"#queries_debug_info table td, #queries_debug_info table th{border:1px solid #A00; padding:0 3px; text-align:center;}\n#queries_debug_info table thead, #queries_debug_info table tbody {color:#A00;}\n#queries_debug_info p {background-color:#F3F3FF; border:1px solid #CCC; margin:12px; padding:4px 6px;}\n#queries_debug_info a:hover {text-decoration:underline;}\n"
      end

[Source]

# File lib/rails-footnotes/notes/queries_note.rb, line 17
      def title
        "Queries (#{@@sql.length})"
      end

Protected Instance methods

[Source]

# File lib/rails-footnotes/notes/queries_note.rb, line 53
        def parse_explain(results)
          table = []
          table << results.fetch_fields.map(&:name)
          results.each{|row| table << row}
          table
        end

[Source]

# File lib/rails-footnotes/notes/queries_note.rb, line 60
        def parse_trace(trace)
          trace.map do |t|
            s = t.split(':')
            %[<a href="#{escape(Footnotes::Filter.prefix("#{RAILS_ROOT}/#{s[0]}", s[1].to_i, 1))}">#{escape(t)}</a><br />]
          end.join
        end

[Source]

# File lib/rails-footnotes/notes/queries_note.rb, line 75
        def print_explain(i, explain)
          mount_table(parse_explain(explain), :id => "qtable_#{i}", :style => 'margin:10px;display:none;')
        end

[Source]

# File lib/rails-footnotes/notes/queries_note.rb, line 67
        def print_name_and_time(name, time)
          "#{escape(name || 'SQL')} (#{sprintf('%f', time)}s)"
        end

[Source]

# File lib/rails-footnotes/notes/queries_note.rb, line 71
        def print_query(query)
          escape(query.to_s.gsub(/(\s)+/, ' ').gsub('`', ''))
        end

[Validate]