class Spectator::MeterId

Identifier for a meter or Measure

Attributes

name[R]
tags[R]

Public Class Methods

new(name, maybe_tags = nil) click to toggle source
# File lib/spectator/meter_id.rb, line 5
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 48
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 27
def key
  if @key.nil?
    hash_key = @name.to_s
    @key = hash_key
    keys = @tags.keys
    keys.sort
    keys.each do |k|
      v = tags[k]
      hash_key += "|#{k}|#{v}"
    end
    @key = hash_key
  end
  @key
end
to_s() click to toggle source

A string representation for debugging purposes

# File lib/spectator/meter_id.rb, line 43
def to_s
  "MeterId{name=#{@name}, tags=#{@tags}}"
end
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 22
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 15
def with_tag(key, value)
  new_tags = @tags.dup
  new_tags[key] = value
  MeterId.new(@name, new_tags)
end