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
17
# File 'lib/debugbar/request.rb', line 8

def initialize(request_id)
  @request_id = request_id
  @models = {}
  @queries = []
  @jobs = []
  @messages = []
  @cache = []
  @logs = []
  @http_calls = []
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

#http_callsObject (readonly)

Returns the value of attribute http_calls.



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

def http_calls
  @http_calls
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.



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

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.



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

def response
  @response
end

Instance Method Details

#add_cache(c) ⇒ Object



56
57
58
# File 'lib/debugbar/request.rb', line 56

def add_cache(c)
  @cache << c
end

#add_http_call(id, request, response, extra) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/debugbar/request.rb', line 64

def add_http_call(id, request, response, extra)
  @http_calls << {
    id: id,
    request: request.to_h,
    response: response.to_h
  }.merge(extra)
end

#add_job(job) ⇒ Object



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

def add_job(job)
  @jobs << job
end

#add_log(l) ⇒ Object



60
61
62
# File 'lib/debugbar/request.rb', line 60

def add_log(l)
  @logs << l
end

#add_msg(msg, extra, source) ⇒ Object



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

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

#add_query(query) ⇒ Object



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

def add_query(query)
  @queries << query
end

#inc_model(name) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/debugbar/request.rb', line 36

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

#to_hObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/debugbar/request.rb', line 72

def to_h
  {
    id: request_id,
    meta: meta,
    request: request.to_h,
    response: response&.to_h,
    models: models,
    queries: queries,
    jobs: jobs,
    messages: messages,
    cache: cache,
    logs: logs,
    http_calls: http_calls,
  }
end

#to_jsonObject



88
89
90
# File 'lib/debugbar/request.rb', line 88

def to_json
  JSON.pretty_generate(to_h)
end