class Spectator::MeterId
Identifier for a meter or Measure
Attributes
name[R]
Public Class Methods
new(name, maybe_tags = nil)
click to toggle source
# File lib/spectator/meter_id.rb, line 6 def initialize(name, maybe_tags = nil) tags = maybe_tags.nil? ? {} : maybe_tags @name = name.to_sym @tags = {} tags.each { |k, v| @tags[k.to_sym] = v.to_sym } @tags.freeze @key = nil end
Public Instance Methods
==(other)
click to toggle source
Compare our id and tags against another MeterId
# File lib/spectator/meter_id.rb, line 62 def ==(other) other.name == @name && other.tags == @tags end
key()
click to toggle source
lazyily compute a key to be used in hashes for efficiency
# File lib/spectator/meter_id.rb, line 48 def key @key ||= begin "#{name}|" << @tags.keys.sort.map do |k| [k, @tags[k]] end.flatten.join('|') end end
to_s()
click to toggle source
A string representation for debugging purposes
# File lib/spectator/meter_id.rb, line 57 def to_s "MeterId{name=#{@name}, tags=#{@tags}}".freeze end
with_default_stat(stat_value)
click to toggle source
with_stat(stat_value)
click to toggle source
Create a new MeterId
with key=statistic and the given value
# File lib/spectator/meter_id.rb, line 32 def with_stat(stat_value) with_tag(:statistic, stat_value) end
with_tag(key, value)
click to toggle source
Create a new MeterId
with a given key and value
# File lib/spectator/meter_id.rb, line 16 def with_tag(key, value) new_tags = @tags.dup new_tags[key] = value MeterId.new(@name, new_tags) end