Class: QueryGuard::Trace::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/query_guard/trace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, context, stats, violations) ⇒ Report

Returns a new instance of Report.



11
12
13
14
15
16
# File 'lib/query_guard/trace.rb', line 11

def initialize(label, context, stats, violations)
  @label = label
  @context = context
  @stats = stats
  @violations = violations
end

Instance Attribute Details

#context ⇒ Object (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/query_guard/trace.rb', line 9

def context
  @context
end

#label ⇒ Object (readonly)

Returns the value of attribute label.



9
10
11
# File 'lib/query_guard/trace.rb', line 9

def label
  @label
end

#stats ⇒ Object (readonly)

Returns the value of attribute stats.



9
10
11
# File 'lib/query_guard/trace.rb', line 9

def stats
  @stats
end

#violations ⇒ Object (readonly)

Returns the value of attribute violations.



9
10
11
# File 'lib/query_guard/trace.rb', line 9

def violations
  @violations
end

Instance Method Details

#fingerprints ⇒ Object



30
31
32
# File 'lib/query_guard/trace.rb', line 30

def fingerprints
  @stats[:fingerprints] || {}
end

#has_violations? ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/query_guard/trace.rb', line 34

def has_violations?
  !@violations.empty?
end

#queries ⇒ Object



26
27
28
# File 'lib/query_guard/trace.rb', line 26

def queries
  @stats[:queries] || []
end

#query_count ⇒ Object



18
19
20
# File 'lib/query_guard/trace.rb', line 18

def query_count
  @stats[:count]
end

#to_h ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/query_guard/trace.rb', line 38

def to_h
  {
    label: @label,
    context: @context,
    query_count: query_count,
    total_duration_ms: total_duration_ms,
    violations: @violations,
    fingerprints: @fingerprints
  }
end

#total_duration_ms ⇒ Object



22
23
24
# File 'lib/query_guard/trace.rb', line 22

def total_duration_ms
  @stats[:total_duration_ms]
end