Class: ActionCost::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/action_cost/middleware.rb

Overview

ActionCost data store

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeData

Returns a new instance of Data.



7
8
9
10
11
12
# File 'lib/action_cost/middleware.rb', line 7

def initialize
  # Per process storage
  @stats_collector = ActionCost::StatsCollector.new
  # Per HTTP request storage
  @request_stats = nil
end

Instance Attribute Details

#request_statsObject (readonly)

Returns the value of attribute request_stats.



5
6
7
# File 'lib/action_cost/middleware.rb', line 5

def request_stats
  @request_stats
end

#stats_collectorObject (readonly)

Returns the value of attribute stats_collector.



5
6
7
# File 'lib/action_cost/middleware.rb', line 5

def stats_collector
  @stats_collector
end

Instance Method Details

#accumulated_statsObject



30
31
32
33
# File 'lib/action_cost/middleware.rb', line 30

def accumulated_stats
  return unless @stats_collector
  @stats_collector.data
end

#end_requestObject



18
19
20
21
22
23
# File 'lib/action_cost/middleware.rb', line 18

def end_request
  return unless @request_stats
  @request_stats.close
  @stats_collector.push(@request_stats)
  @request_stats = nil
end

#push_sql_parser(parser) ⇒ Object



25
26
27
28
# File 'lib/action_cost/middleware.rb', line 25

def push_sql_parser(parser)
  return unless @request_stats
  @request_stats.push(parser)
end

#start_request(env) ⇒ Object



14
15
16
# File 'lib/action_cost/middleware.rb', line 14

def start_request(env)
  @request_stats = ActionCost::RequestStats.new(env)
end