Class: FnordMetric::Context

Inherits:
Object
  • Object
show all
Includes:
GaugeModifiers
Defined in:
lib/fnordmetric/context.rb

Defined Under Namespace

Classes: Proxy

Instance Method Summary collapse

Methods included from GaugeModifiers

#assure_has_series!, #assure_non_progressive!, #assure_series_exists!, #assure_three_dimensional!, #assure_two_dimensional!, #incr, #incr_avg, #incr_denominator, #incr_field, #incr_field_by, #incr_fraction, #incr_numerator, #incr_tick, #incr_uniq, #parse_numeric, #set_field, #set_value

Constructor Details

#initialize(opts, block) ⇒ Context

Returns a new instance of Context.



17
18
19
20
# File 'lib/fnordmetric/context.rb', line 17

def initialize(opts, block)
  @block = block
  @opts = opts    
end

Instance Method Details

#call(event, redis) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/fnordmetric/context.rb', line 22

def call(event, redis)
  @redis = redis
  @event = event    
  proxy.instance_eval(&@block)
rescue Exception => e
  raise e if ENV['FNORDMETRIC_ENV'] == 'test'
  puts "error: #{e.message}"
  puts e.backtrace.push("").join("\n") if ENV['FNORDMETRIC_ENV'] == 'dev'
end

#dispatch(method, *args, &block) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fnordmetric/context.rb', line 36

def dispatch(method, *args, &block)
  if args.size > 0 && @opts[:gauges][args[0]].try(:renderable?)
    @opts[:gauges][args.delete_at(0)].execute(method, *args.unshift(self), &block)
  else
    send(method, *args, &block)
  end
rescue Exception => e
  raise e if ENV['FNORDMETRIC_ENV'] == 'test'
  puts "error: #{e.message}"
  puts e.backtrace.push("\n").join("\n") if ENV['FNORDMETRIC_ENV'] == 'dev'
end

#proxyObject



32
33
34
# File 'lib/fnordmetric/context.rb', line 32

def proxy
  @proxy ||= Proxy.new(self)
end

#redis_exec(*args) ⇒ Object



48
49
50
# File 'lib/fnordmetric/context.rb', line 48

def redis_exec(*args)
  @redis.send(*args)
end