Module: MerbFootnotes::Instrumentation

Defined in:
lib/merb_footnotes/instrumentation.rb

Defined Under Namespace

Modules: DataMapper, Merb

Class Method Summary collapse

Class Method Details

.attrs_for(query) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/merb_footnotes/instrumentation.rb', line 34

def self.attrs_for(query)
  [
    [ :repository, query.repository.name ],
    [ :model,      query.model           ],
    [ :fields,     query.fields          ],
    [ :links,      query.links           ],
    [ :conditions, query.conditions      ],
    [ :order,      query.order           ],
    [ :limit,      query.limit           ],
    [ :offset,     query.offset          ],
    [ :reload,     query.reload?         ],
    [ :unique,     query.unique?         ]
  ]
end

.format_query(query) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/merb_footnotes/instrumentation.rb', line 49

def self.format_query(query)
  rows = attrs_for(query).map do |set|
    %(<tr><th>%s</th><td><pre>%s</pre></td></tr>) % set.map { |item|
      pretty item
    }
  end
  "<table>%s</table>" % rows.join
end

.format_sql(query, statement, attributes = nil) ⇒ Object



29
30
31
32
# File 'lib/merb_footnotes/instrumentation.rb', line 29

def self.format_sql(query, statement, attributes = nil)
  values = query.bind_values + (attributes ? attributes.values : [])
  [statement, "<b>Values:</b> " + CGI.escapeHTML(values.inspect)].join("<br/>")
end

.pretty(value) ⇒ Object



25
26
27
# File 'lib/merb_footnotes/instrumentation.rb', line 25

def self.pretty(value)
  CGI.escapeHTML(PP.pp(value, ''))
end