Class: Split::ExperimentCatalog
- Inherits:
-
Object
- Object
- Split::ExperimentCatalog
- Defined in:
- lib/split/experiment_catalog.rb
Class Method Summary collapse
-
.all ⇒ Object
Return all experiments.
-
.all_active_first ⇒ Object
Return experiments without a winner (considered “active”) first.
- .find(name) ⇒ Object
- .find_or_create(metric_descriptor, control = nil, *alternatives) ⇒ Object
- .find_or_initialize(metric_descriptor, control = nil, *alternatives) ⇒ Object
Class Method Details
.all ⇒ Object
Return all experiments
6 7 8 9 |
# File 'lib/split/experiment_catalog.rb', line 6 def self.all # Call compact to prevent nil experiments from being returned -- seems to happen during gem upgrades Split.redis.smembers(:experiments).map { |e| find(e) }.compact end |
.all_active_first ⇒ Object
Return experiments without a winner (considered “active”) first
12 13 14 |
# File 'lib/split/experiment_catalog.rb', line 12 def self.all_active_first all.partition { |e| not e.winner }.map { |es| es.sort_by(&:name) }.flatten end |
.find(name) ⇒ Object
16 17 18 |
# File 'lib/split/experiment_catalog.rb', line 16 def self.find(name) Experiment.find(name) end |
.find_or_create(metric_descriptor, control = nil, *alternatives) ⇒ Object
33 34 35 36 |
# File 'lib/split/experiment_catalog.rb', line 33 def self.find_or_create(metric_descriptor, control = nil, *alternatives) experiment = find_or_initialize(metric_descriptor, control, *alternatives) experiment.save end |
.find_or_initialize(metric_descriptor, control = nil, *alternatives) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/split/experiment_catalog.rb', line 20 def self.find_or_initialize(metric_descriptor, control = nil, *alternatives) # Check if array is passed to ab_test # e.g. ab_test('name', ['Alt 1', 'Alt 2', 'Alt 3']) if control.is_a?(Array) && alternatives.length.zero? control, alternatives = control.first, control[1..-1] end experiment_name_with_version, goals = normalize_experiment(metric_descriptor) experiment_name = experiment_name_with_version.to_s.split(":")[0] Split::Experiment.new(experiment_name, alternatives: [control].compact + alternatives, goals: goals) end |