Class: Statsby::Context

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

Overview

This is meant to be used as a thin layer over a client or another context as a way to organize tags.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, tags = {}) ⇒ Context

Returns a new instance of Context.



10
11
12
13
# File 'lib/statsby/context.rb', line 10

def initialize(client, tags = {})
  self.client = client
  self.tags = Statsby::TagSet.from_hash(tags)
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/statsby/context.rb', line 8

def client
  @client
end

#tagsObject

Returns the value of attribute tags.



8
9
10
# File 'lib/statsby/context.rb', line 8

def tags
  @tags
end

Instance Method Details

#counter(metric_name, value, local_tags = {}) ⇒ Object



15
16
17
18
# File 'lib/statsby/context.rb', line 15

def counter(metric_name, value, local_tags = {})
  combined_tags = tags.merge(local_tags)
  client.counter(metric_name, value, combined_tags)
end

#format_message(metric_name, value, type, message_tags = {}) ⇒ Object



39
40
41
42
# File 'lib/statsby/context.rb', line 39

def format_message(metric_name, value, type, message_tags = {})
  combined_tags = tags.merge(message_tags)
  client.format_message(metric_name, value, type, combined_tags)
end

#format_tags(message_tags = {}) ⇒ Object



35
36
37
# File 'lib/statsby/context.rb', line 35

def format_tags(message_tags = {})
  client.format_tags(tags.merge(message_tags))
end

#gauge(metric_name, value, local_tags = {}) ⇒ Object



20
21
22
23
# File 'lib/statsby/context.rb', line 20

def gauge(metric_name, value, local_tags = {})
  combined_tags = tags.merge(local_tags)
  client.gauge(metric_name, value, combined_tags)
end

#set(metric_name, value, local_tags = {}) ⇒ Object



30
31
32
33
# File 'lib/statsby/context.rb', line 30

def set(metric_name, value, local_tags = {})
  combined_tags = tags.merge(local_tags)
  client.set(metric_name, value, combined_tags)
end

#subcontext(tags = {}) ⇒ Object



44
45
46
# File 'lib/statsby/context.rb', line 44

def subcontext(tags = {})
  Statsby::Context.new(self, tags)
end

#timing(metric_name, value, local_tags = {}) ⇒ Object



25
26
27
28
# File 'lib/statsby/context.rb', line 25

def timing(metric_name, value, local_tags = {})
  combined_tags = tags.merge(local_tags)
  client.timing(metric_name, value, combined_tags)
end