Module: Vanity::Metric::Definition

Defined in:
lib/vanity/metric/base.rb

Overview

These methods are available when defining a metric in a file loaded from the experiments/metrics directory.

For example:

$ cat experiments/metrics/yawn_sec
metric "Yawns/sec" do
  description "Most boring metric ever"
end

Since:

  • 1.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#playgroundObject (readonly)

Since:

  • 1.1.0



21
22
23
# File 'lib/vanity/metric/base.rb', line 21

def playground
  @playground
end

Instance Method Details

#metric(name, &block) ⇒ Object

Defines a new metric, using the class Vanity::Metric.

Since:

  • 1.1.0



24
25
26
27
28
29
30
# File 'lib/vanity/metric/base.rb', line 24

def metric(name, &block)
  raise "Metric #{@metric_id} already defined in playground" if playground.metrics[@metric_id]

  metric = Metric.new(playground, name.to_s, @metric_id)
  metric.instance_eval(&block)
  playground.metrics[@metric_id] = metric
end

#new_binding(playground, id) ⇒ Object

Since:

  • 1.1.0



32
33
34
35
36
# File 'lib/vanity/metric/base.rb', line 32

def new_binding(playground, id)
  @playground = playground
  @metric_id = id
  binding
end