Class: Debugbar::Request
- Inherits:
-
Object
- Object
- Debugbar::Request
- Defined in:
- lib/debugbar/request.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#http_calls ⇒ Object
readonly
Returns the value of attribute http_calls.
-
#jobs ⇒ Object
readonly
Returns the value of attribute jobs.
-
#logs ⇒ Object
readonly
Returns the value of attribute logs.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#models ⇒ Object
readonly
Returns the value of attribute models.
-
#queries ⇒ Object
readonly
Returns the value of attribute queries.
-
#request ⇒ Object
Returns the value of attribute request.
-
#request_id ⇒ Object
(also: #id)
readonly
Returns the value of attribute request_id.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #add_cache(c) ⇒ Object
- #add_http_call(id, request, response, extra) ⇒ Object
- #add_job(job) ⇒ Object
- #add_log(l) ⇒ Object
- #add_msg(msg, extra, source) ⇒ Object
- #add_query(query) ⇒ Object
- #inc_model(name) ⇒ Object
-
#initialize(request_id) ⇒ Request
constructor
A new instance of Request.
- #to_h ⇒ Object
- #to_json ⇒ Object
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
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
3 4 5 |
# File 'lib/debugbar/request.rb', line 3 def cache @cache end |
#http_calls ⇒ Object (readonly)
Returns the value of attribute http_calls.
3 4 5 |
# File 'lib/debugbar/request.rb', line 3 def http_calls @http_calls end |
#jobs ⇒ Object (readonly)
Returns the value of attribute jobs.
3 4 5 |
# File 'lib/debugbar/request.rb', line 3 def jobs @jobs end |
#logs ⇒ Object (readonly)
Returns the value of attribute logs.
3 4 5 |
# File 'lib/debugbar/request.rb', line 3 def logs @logs end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
3 4 5 |
# File 'lib/debugbar/request.rb', line 3 def @messages end |
#meta ⇒ Object
Returns the value of attribute meta.
3 4 5 |
# File 'lib/debugbar/request.rb', line 3 def @meta end |
#models ⇒ Object (readonly)
Returns the value of attribute models.
3 4 5 |
# File 'lib/debugbar/request.rb', line 3 def models @models end |
#queries ⇒ Object (readonly)
Returns the value of attribute queries.
3 4 5 |
# File 'lib/debugbar/request.rb', line 3 def queries @queries end |
#request ⇒ Object
Returns the value of attribute request.
3 4 5 |
# File 'lib/debugbar/request.rb', line 3 def request @request end |
#request_id ⇒ Object (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 |
#response ⇒ Object
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_h ⇒ Object
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: , request: request.to_h, response: response&.to_h, models: models, queries: queries, jobs: jobs, messages: , cache: cache, logs: logs, http_calls: http_calls, } end |
#to_json ⇒ Object
88 89 90 |
# File 'lib/debugbar/request.rb', line 88 def to_json JSON.pretty_generate(to_h) end |