Class: MetricSense::Context

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collector) ⇒ Context

Returns a new instance of Context.



88
89
90
91
# File 'lib/metricsense.rb', line 88

def initialize(collector)
  @collector = collector
  @events = {}
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



93
94
95
# File 'lib/metricsense.rb', line 93

def events
  @events
end

Instance Method Details

#clear!Object



101
102
103
104
# File 'lib/metricsense.rb', line 101

def clear!
  @events.clear
  nil
end

#event(tag) ⇒ Object Also known as: []



95
96
97
# File 'lib/metricsense.rb', line 95

def event(tag)
  @events[tag] ||= Event.new(tag)
end

#measure!Object



106
107
108
109
110
111
112
113
114
# File 'lib/metricsense.rb', line 106

def measure!
  return nil unless @collector
  @events.keys.each {|k|
    event = @events[k]
    @collector.measure(event) if event.tag
    @events.delete(k)
  }
  nil
end