Class: Trashed::Meter

Inherits:
Object
  • Object
show all
Defined in:
lib/trashed/meter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Meter

Returns a new instance of Meter.



5
6
7
8
# File 'lib/trashed/meter.rb', line 5

def initialize(&block)
  @counters, @gauges = {}, {}
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#countersObject (readonly)

Returns the value of attribute counters.



3
4
5
# File 'lib/trashed/meter.rb', line 3

def counters
  @counters
end

#gauges(name, &block) ⇒ Object (readonly)

Returns the value of attribute gauges.



3
4
5
# File 'lib/trashed/meter.rb', line 3

def gauges
  @gauges
end

Instance Method Details

#countObject



11
# File 'lib/trashed/meter.rb', line 11

def count; read @counters end

#counts(name, &block) ⇒ Object



10
# File 'lib/trashed/meter.rb', line 10

def counts(name, &block) @counters[name] = block end

#gaugeObject



14
# File 'lib/trashed/meter.rb', line 14

def gauge; read @gauges end

#instrumentObject



16
17
18
19
20
# File 'lib/trashed/meter.rb', line 16

def instrument
  before = count
  yield
  delta before, count
end