Module: Rack::Insight::Database::RequestDataClient

Included in:
Panel, SpeedTracer::TraceApp
Defined in:
lib/rack/insight/database.rb

Overview

Classes including this module must define the following structure:

class FooBar
  include Rack::Insight::Database
  class << self
    attr_accessor :has_table
  end
  # Setting as below is only required when not using a table (Why are you including this module then?)
  # self.has_table = false
end

TODO: Move the has_table definition into this module’s included hook.

Instance Method Summary collapse

Instance Method Details

#count(request_id) ⇒ Object



59
60
61
# File 'lib/rack/insight/database.rb', line 59

def count(request_id)
  self.class.table.count_for_request(request_id)
end

#key_sql_template(sql) ⇒ Object



26
27
28
# File 'lib/rack/insight/database.rb', line 26

def key_sql_template(sql)
  self.class.key_sql_template = sql
end

#retrieve(request_id) ⇒ Object



55
56
57
# File 'lib/rack/insight/database.rb', line 55

def retrieve(request_id)
  self.class.table.for_request(request_id)
end

#store(env, *keys_and_value) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rack/insight/database.rb', line 39

def store(env, *keys_and_value)
  return if env.nil?
  request_id = env["rack-insight.request-id"]
  return if request_id.nil?

  value = keys_and_value[-1]
  keys = keys_and_value[0...-1]

  #puts "value: #{value}"
  #puts "keys: #{keys}"
  #puts "table: #{self.class.table.inspect}"
  #puts "@key_sql_template: #{self.class.key_sql_template}"
  #puts "class: #{self.class.inspect}"
  self.class.table.store(request_id, value, self.class.key_sql_template % keys)
end

#table_lengthObject



63
64
65
# File 'lib/rack/insight/database.rb', line 63

def table_length
  self.class.table.length
end

#table_setup(name, *keys) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/rack/insight/database.rb', line 30

def table_setup(name, *keys)
  self.class.has_table = true
  self.class.table = DataTable.new(name, *keys)
  if keys.empty?
    self.class.key_sql_template = ''
  end
  self.class.table
end