Class: Debugbar::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/debugbar/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_id) ⇒ Request

Returns a new instance of Request.



8
9
10
11
12
13
14
15
16
# File 'lib/debugbar/request.rb', line 8

def initialize(request_id)
  @request_id = request_id
  @models = {}
  @queries = []
  @jobs = []
  @messages = []
  @cache = []
  @logs = []
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



3
4
5
# File 'lib/debugbar/request.rb', line 3

def cache
  @cache
end

#headersObject

Returns the value of attribute headers.



6
7
8
# File 'lib/debugbar/request.rb', line 6

def headers
  @headers
end

#jobsObject (readonly)

Returns the value of attribute jobs.



3
4
5
# File 'lib/debugbar/request.rb', line 3

def jobs
  @jobs
end

#logsObject (readonly)

Returns the value of attribute logs.



3
4
5
# File 'lib/debugbar/request.rb', line 3

def logs
  @logs
end

#messagesObject (readonly)

Returns the value of attribute messages.



3
4
5
# File 'lib/debugbar/request.rb', line 3

def messages
  @messages
end

#metaObject

Returns the value of attribute meta.



3
4
5
# File 'lib/debugbar/request.rb', line 3

def meta
  @meta
end

#modelsObject (readonly)

Returns the value of attribute models.



3
4
5
# File 'lib/debugbar/request.rb', line 3

def models
  @models
end

#queriesObject (readonly)

Returns the value of attribute queries.



3
4
5
# File 'lib/debugbar/request.rb', line 3

def queries
  @queries
end

#requestObject

Returns the value of attribute request.



6
7
8
# File 'lib/debugbar/request.rb', line 6

def request
  @request
end

#request_idObject (readonly) Also known as: id

Returns the value of attribute request_id.



3
4
5
# File 'lib/debugbar/request.rb', line 3

def request_id
  @request_id
end

#responseObject

Returns the value of attribute response.



6
7
8
# File 'lib/debugbar/request.rb', line 6

def response
  @response
end

Instance Method Details

#add_cache(c) ⇒ Object



47
48
49
# File 'lib/debugbar/request.rb', line 47

def add_cache(c)
  @cache << c
end

#add_job(job) ⇒ Object



39
40
41
# File 'lib/debugbar/request.rb', line 39

def add_job(job)
  @jobs << job
end

#add_log(l) ⇒ Object



51
52
53
# File 'lib/debugbar/request.rb', line 51

def add_log(l)
  @logs << l
end

#add_msg(msg, extra, source) ⇒ Object



43
44
45
# File 'lib/debugbar/request.rb', line 43

def add_msg(msg, extra, source)
  @messages << {id: SecureRandom.hex(8), msg: msg, extra: extra, source: source}
end

#add_query(query) ⇒ Object



35
36
37
# File 'lib/debugbar/request.rb', line 35

def add_query(query)
  @queries << query
end

#inc_model(name) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/debugbar/request.rb', line 27

def inc_model(name)
  if @models[name]
    @models[name] += 1
  else
    @models[name] = 1
  end
end

#to_hObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/debugbar/request.rb', line 55

def to_h
  {
    id: request_id,
    meta: meta,
    request: request_hash,
    response: response_hash,
    models: models,
    queries: queries,
    jobs: jobs,
    messages: messages,
    cache: cache,
    logs: logs,
  }
end

#to_jsonObject



70
71
72
# File 'lib/debugbar/request.rb', line 70

def to_json
  JSON.pretty_generate(to_h)
end