Module: Hallmonitor::Monitored::ClassMethods

Defined in:
lib/hallmonitor/monitored.rb

Instance Method Summary collapse

Instance Method Details

#count_for(method_sym, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/hallmonitor/monitored.rb', line 18

def count_for(method_sym, options={})
  metric_name = options[:metric_name] || "#{self.underscore(self.name)}.#{method_sym.to_s}.count"
  self.send(:define_method, "#{method_sym.to_s}_with_hallmonitor_counter") do |*args|
    emit(metric_name)
    self.send("#{method_sym.to_s}_without_hallmonitor_counter".to_sym, *args)
  end

  alias_method "#{method_sym.to_s}_without_hallmonitor_counter".to_sym, method_sym
  alias_method method_sym, "#{method_sym.to_s}_with_hallmonitor_counter".to_sym
end

#timer_for(method_sym, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/hallmonitor/monitored.rb', line 6

def timer_for(method_sym, options={})
  metric_name = options[:metric_name] || "#{self.underscore(self.name)}.#{method_sym.to_s}.time"
  self.send(:define_method, "#{method_sym.to_s}_with_hallmonitor_timer") do |*args|
    watch(metric_name) do 
      self.send("#{method_sym.to_s}_without_hallmonitor_timer".to_sym, *args)
    end
  end

  alias_method "#{method_sym.to_s}_without_hallmonitor_timer".to_sym, method_sym
  alias_method method_sym, "#{method_sym.to_s}_with_hallmonitor_timer".to_sym
end

#underscore(value) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/hallmonitor/monitored.rb', line 29

def underscore(value)
  word = value.dup
  word.gsub!(/::/, '/')
  word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  word.tr!("-", "_")
  word.downcase!
  word
end