Skip to content

Commit

Permalink
a submetric created by an experiment should know the experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Adkisson committed Jul 13, 2010
1 parent 833afbe commit 43e4524
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/modesty/experiment.rb
Expand Up @@ -25,9 +25,9 @@ def new_experiment(slug, &block)
exp.metrics.each do |m|
m.experiments << exp
exp.alternatives.each do |a|
Modesty.new_metric(m.slug/exp.slug/a, m)
Modesty.new_metric(m.slug/exp.slug/a, :parent => m, :experiment => exp)
end
endexp
end
add_experiment(exp)
exp
end
Expand Down
10 changes: 8 additions & 2 deletions lib/modesty/metric.rb
Expand Up @@ -25,8 +25,14 @@ def add_metric(metric)
self.metrics[metric.slug] = metric
end

def new_metric(slug, parent=nil, &block)
metric = Metric.new(slug, parent)
def new_metric(slug, parent=nil, options={}, &block)
if parent.is_a? Hash
options=parent
else
options[:parent] = parent
end

metric = Metric.new(slug, options)
yield Metric::Builder.new(metric) if block_given?
add_metric(metric)
metric
Expand Down
6 changes: 4 additions & 2 deletions lib/modesty/metric/base.rb
Expand Up @@ -13,16 +13,18 @@ def data_type(name)
attr_reader *ATTRIBUTES
attr_reader :slug
attr_reader :parent
attr_reader :experiment

# metrics should know what experiments use them,
# to enable smart tracking.
def experiments
@experiments ||= []
end

def initialize(slug, parent=nil)
def initialize(slug, options={})
@slug = slug
@parent = parent
@parent = options[:parent]
@experiment = options[:experiment]
end

def inspect
Expand Down

0 comments on commit 43e4524

Please sign in to comment.