Sha256: 5bdb74f965dd958999cc178a26599b306eba6b000c855076b0cabc09cf254596

Contents?: true

Size: 1.29 KB

Versions: 20

Compression:

Stored size: 1.29 KB

Contents

class FnordMetric::Context

  include FnordMetric::GaugeModifiers

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

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

private

  def session_key
    @event[:_session_key]
  end

  def data
  	@event
  end

  def key(gauge)
    fetch_gauge(gauge).key
  end

  def time
    @event[:_time].to_i
  end

protected

  def fetch_gauge(_gauge)
    _gauge.is_a?(FnordMetric::Gauge) ? _gauge : @opts[:gauges].fetch(_gauge)
  rescue
    error! "error: gauge '#{_gauge}' is undefined"
  end

  def error!(msg)
    FnordMetric.error!(msg)
  end

  def assure_two_dimensional!(gauge)
    return true if gauge.two_dimensional?
    error! "error: #{caller[0].split(" ")[-1]} can only be used with 2-dimensional gauges" 
  end

  def assure_three_dimensional!(gauge)
    return true unless gauge.two_dimensional?
    error! "error: #{caller[0].split(" ")[-1]} can only be used with 3-dimensional gauges" 
  end

  def assure_non_progressive!(gauge)
    return true unless gauge.progressive?
    error! "error: #{caller[0].split(" ")[-1]} can only be used with non-progressive gauges" 
  end

end
    

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
fnordmetric-0.7.5 lib/fnordmetric/context.rb
fnordmetric-0.7.4 lib/fnordmetric/context.rb
fnordmetric-0.7.3 lib/fnordmetric/context.rb
fnordmetric-0.7.1 lib/fnordmetric/context.rb
fnordmetric-0.7.0 lib/fnordmetric/context.rb
fnordmetric-0.6.6 lib/fnordmetric/context.rb
fnordmetric-0.6.5 lib/fnordmetric/context.rb
fnordmetric-0.6.4 lib/fnordmetric/context.rb
fnordmetric-0.6.3 lib/fnordmetric/context.rb
fnordmetric-0.6.2 lib/fnordmetric/context.rb
fnordmetric-0.6.1 lib/fnordmetric/context.rb
fnordmetric-0.6.0 lib/fnordmetric/context.rb
fnordmetric-0.5.9 lib/fnordmetric/context.rb
fnordmetric-0.5.8 lib/fnordmetric/context.rb
fnordmetric-0.5.7 lib/fnordmetric/context.rb
fnordmetric-0.5.6 lib/fnordmetric/context.rb
fnordmetric-0.5.5 lib/fnordmetric/context.rb
fnordmetric-0.5.4 lib/fnordmetric/context.rb
fnordmetric-0.5.3 lib/fnordmetric/context.rb
fnordmetric-0.5.2 lib/fnordmetric/context.rb