class NewRelic::MetricSpec

this struct uniquely defines a metric, optionally inside the call scope of another metric

Constants

EMPTY_SCOPE
LENGTH_RANGE
MAX_LENGTH

the maximum length of a metric name or metric scope

Attributes

name[R]
scope[R]

Public Class Methods

new(metric_name = '', metric_scope = nil) click to toggle source
# File lib/new_relic/metric_spec.rb, line 15
def initialize(metric_name = '', metric_scope = nil)
  if metric_name.to_s.length > MAX_LENGTH
    @name = metric_name.to_s[LENGTH_RANGE]
  else
    @name = metric_name.to_s
  end

  if metric_scope
    if metric_scope.to_s.length > MAX_LENGTH
      @scope = metric_scope.to_s[LENGTH_RANGE]
    else
      @scope = metric_scope.to_s
    end
  else
    @scope = EMPTY_SCOPE
  end
end

Public Instance Methods

<=>(o) click to toggle source
# File lib/new_relic/metric_spec.rb, line 60
def <=>(o)
  namecmp = self.name <=> o.name
  return namecmp if namecmp != 0

  return (self.scope || '') <=> (o.scope || '')
end
==(o) click to toggle source
# File lib/new_relic/metric_spec.rb, line 33
def ==(o)
  self.eql?(o)
end
eql?(o) click to toggle source
# File lib/new_relic/metric_spec.rb, line 37
def eql?(o)
  @name == o.name && @scope == o.scope
end
hash() click to toggle source
# File lib/new_relic/metric_spec.rb, line 41
def hash
  [@name, @scope].hash
end
inspect() click to toggle source
# File lib/new_relic/metric_spec.rb, line 51
def inspect
  "#<NewRelic::MetricSpec '#{name}':'#{scope}'>"
end
to_json(*a) click to toggle source
# File lib/new_relic/metric_spec.rb, line 55
def to_json(*a)
  {'name' => name,
   'scope' => scope}.to_json(*a)
end
to_s() click to toggle source
# File lib/new_relic/metric_spec.rb, line 45
def to_s
  return name if scope.empty?

  "#{name}:#{scope}"
end