class FnordMetric::Context
Public Class Methods
new(opts, block)
click to toggle source
# File lib/fnordmetric/context.rb, line 17 def initialize(opts, block) @block = block @opts = opts end
Public Instance Methods
call(event, redis, namespace)
click to toggle source
# File lib/fnordmetric/context.rb, line 22 def call(event, redis, namespace) @redis = redis @event = event @namespace = namespace 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)
click to toggle source
# File lib/fnordmetric/context.rb, line 41 def dispatch(method, *args, &block) if args.size > 0 && gauges[args[0]].try(:renderable?) 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
namespace()
click to toggle source
# File lib/fnordmetric/context.rb, line 37 def namespace @namespace end
proxy()
click to toggle source
# File lib/fnordmetric/context.rb, line 33 def proxy @proxy ||= Proxy.new(self) end
redis_exec(*args)
click to toggle source
# File lib/fnordmetric/context.rb, line 53 def redis_exec(*args) @redis.send(*args) end
Protected Instance Methods
error!(msg)
click to toggle source
# File lib/fnordmetric/context.rb, line 91 def error!(msg) FnordMetric.error(msg) end
fetch_gauge(_gauge)
click to toggle source
# File lib/fnordmetric/context.rb, line 85 def fetch_gauge(_gauge) _gauge.is_a?(FnordMetric::Gauge) ? _gauge : gauges.fetch(_gauge) rescue error! "error: gauge '#{_gauge}' is undefined" end
Private Instance Methods
data()
click to toggle source
# File lib/fnordmetric/context.rb, line 63 def data @event end
gauges()
click to toggle source
# File lib/fnordmetric/context.rb, line 79 def gauges @namespace.gauges end
key(gauge)
click to toggle source
# File lib/fnordmetric/context.rb, line 67 def key(gauge) fetch_gauge(gauge).key end
session_key()
click to toggle source
# File lib/fnordmetric/context.rb, line 59 def session_key @event[:_session_key] end
time()
click to toggle source
# File lib/fnordmetric/context.rb, line 71 def time @event[:_time].to_i end
type()
click to toggle source
# File lib/fnordmetric/context.rb, line 75 def type @event[:_type].to_sym end