Module: FiverunsTuneupMerb::Instrumentation

Defined in:
lib/fiveruns_tuneup_merb/instrumentation.rb

Defined Under Namespace

Modules: DataMapper, Merb

Class Method Summary collapse

Class Method Details

.attrs_for(query) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fiveruns_tuneup_merb/instrumentation.rb', line 29

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_filters(filters) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fiveruns_tuneup_merb/instrumentation.rb', line 11

def self.format_filters(filters)
  sets = filters.map do |filter, opts|
    content = if filter.is_a?(Proc)
      where = filter.inspect[/@(.+)>$/, 1]
      "Proc at %s with options %s" % [Fiveruns::Tuneup.editor_link_line(where), pretty(opts)]
    else
      "%s with options %s" % [pretty(filter), pretty(opts)]
     end
    %(<li>%s</li>) % content
  end
  "<ul>%s</ul>" % sets.join("\n")
end

.format_query(query) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/fiveruns_tuneup_merb/instrumentation.rb', line 44

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



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

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



7
8
9
# File 'lib/fiveruns_tuneup_merb/instrumentation.rb', line 7

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