Class: ScoutRails::MetricMeta

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

Overview

Contains the meta information associated with a metric. Used to lookup Metrics in to Store’s metric_hash.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metric_name, options = {}) ⇒ MetricMeta

Returns a new instance of MetricMeta.



3
4
5
6
7
8
9
# File 'lib/scout_rails/metric_meta.rb', line 3

def initialize(metric_name, options = {})
  @metric_name = metric_name
  @metric_id = nil
  @scope = Thread::current[:scout_sub_scope] || Thread::current[:scout_scope_name]
  @desc = options[:desc]
  @extra = {}
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



12
13
14
# File 'lib/scout_rails/metric_meta.rb', line 12

def client_id
  @client_id
end

#descObject

Returns the value of attribute desc.



13
14
15
# File 'lib/scout_rails/metric_meta.rb', line 13

def desc
  @desc
end

#extraObject

Returns the value of attribute extra.



13
14
15
# File 'lib/scout_rails/metric_meta.rb', line 13

def extra
  @extra
end

#metric_idObject

Returns the value of attribute metric_id.



10
11
12
# File 'lib/scout_rails/metric_meta.rb', line 10

def metric_id
  @metric_id
end

#metric_nameObject

Returns the value of attribute metric_name.



10
11
12
# File 'lib/scout_rails/metric_meta.rb', line 10

def metric_name
  @metric_name
end

#scopeObject

Returns the value of attribute scope.



11
12
13
# File 'lib/scout_rails/metric_meta.rb', line 11

def scope
  @scope
end

Instance Method Details

#==(o) ⇒ Object



20
21
22
# File 'lib/scout_rails/metric_meta.rb', line 20

def ==(o)
  self.eql?(o)
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/scout_rails/metric_meta.rb', line 31

def eql?(o)
 self.class == o.class && metric_name.downcase.eql?(o.metric_name.downcase) && scope == o.scope && client_id == o.client_id && desc == o.desc
end

#hashObject



24
25
26
27
28
29
# File 'lib/scout_rails/metric_meta.rb', line 24

def hash
  h = metric_name.downcase.hash
  h ^= scope.downcase.hash unless scope.nil?
  h ^= desc.downcase.hash unless desc.nil?
  h
end

#to_json(*a) ⇒ Object

To avoid conflicts with different JSON libaries



16
17
18
# File 'lib/scout_rails/metric_meta.rb', line 16

def to_json(*a)
   %Q[{"metric_id":#{metric_id || 'null'},"metric_name":#{metric_name.to_json},"scope":#{scope.to_json || 'null'}}]
end