Class: Rack::Insight::MongoPanel::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/insight/panels/mongo_panel/stats.rb

Defined Under Namespace

Classes: Query

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStats

Returns a new instance of Stats.



22
23
24
25
26
# File 'lib/rack/insight/panels/mongo_panel/stats.rb', line 22

def initialize
  @queries = []
  @calls = 0
  @time = 0.0
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



19
20
21
# File 'lib/rack/insight/panels/mongo_panel/stats.rb', line 19

def calls
  @calls
end

#queriesObject (readonly)

Returns the value of attribute queries.



20
21
22
# File 'lib/rack/insight/panels/mongo_panel/stats.rb', line 20

def queries
  @queries
end

Instance Method Details

#display_timeObject



34
35
36
# File 'lib/rack/insight/panels/mongo_panel/stats.rb', line 34

def display_time
  "%.2fms" % time
end

#record_call(time, command) ⇒ Object



28
29
30
31
32
# File 'lib/rack/insight/panels/mongo_panel/stats.rb', line 28

def record_call(time, command)
  @queries << Query.new(time, command)
  @calls += 1
  @time += time
end

#timeObject



38
39
40
41
42
# File 'lib/rack/insight/panels/mongo_panel/stats.rb', line 38

def time
  @queries.inject(0) do |memo, query|
    memo + query.time
  end
end