Class: Rack::DevInsight::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/dev_insight/result.rb,
lib/rack/dev_insight/result/sql.rb,
lib/rack/dev_insight/result/apis.rb,
lib/rack/dev_insight/result/sql/queries.rb,
lib/rack/dev_insight/result/sql/errored_queries.rb,
lib/rack/dev_insight/result/sql/crud_aggregations.rb,
lib/rack/dev_insight/result/sql/normalized_aggregations.rb

Defined Under Namespace

Classes: Apis, Request, Sql

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Result

Returns a new instance of Result.



22
23
24
25
26
27
# File 'lib/rack/dev_insight/result.rb', line 22

def initialize(id)
  @id = id
  @request = Request.new
  @sql = Sql.new
  @apis = Apis.new
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



20
21
22
# File 'lib/rack/dev_insight/result.rb', line 20

def id
  @id
end

Class Method Details

.build_backtrace_item(original, path, line) ⇒ Object



11
12
13
# File 'lib/rack/dev_insight/result.rb', line 11

def build_backtrace_item(original, path, line)
  Sql::Queries::TraceInfo.new(original, path, line)
end

.build_header(field, value) ⇒ Object



15
16
17
# File 'lib/rack/dev_insight/result.rb', line 15

def build_header(field, value)
  Apis::Header.new(field, value)
end

Instance Method Details

#add_api(method:, url:, request_headers:, request_body:, status:, response_headers:, response_body:, backtrace:, duration:) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rack/dev_insight/result.rb', line 37

def add_api(
  method:,
  url:,
  request_headers:,
  request_body:,
  status:,
  response_headers:,
  response_body:,
  backtrace:,
  duration:
)
  @apis.add(
    method,
    url,
    request_headers,
    request_body,
    status,
    response_headers,
    response_body,
    backtrace,
    duration,
  )
end

#add_sql(dialect:, statement:, binds:, backtrace:, duration:) ⇒ Object



33
34
35
# File 'lib/rack/dev_insight/result.rb', line 33

def add_sql(dialect:, statement:, binds:, backtrace:, duration:)
  @sql.add(dialect, statement, binds, backtrace, duration)
end

#attributesObject



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rack/dev_insight/result.rb', line 61

def attributes
  {
    id: @id,
    status: @request.status,
    method: @request.http_method,
    path: @request.path,
    duration: @request.duration,
    sql: @sql.attributes,
    apis: @apis.attributes,
  }
end

#set_request(status:, http_method:, path:, duration:) ⇒ Object



29
30
31
# File 'lib/rack/dev_insight/result.rb', line 29

def set_request(status:, http_method:, path:, duration:)
  @request = Request.new(status, http_method, path, duration)
end

#to_response_jsonObject



73
74
75
# File 'lib/rack/dev_insight/result.rb', line 73

def to_response_json
  Camelizer.camelize_keys(attributes).to_json
end