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(label, *alternatives) ⇒ Object
Class Method Details
.all ⇒ Object
Return all experiments
4 5 6 7 |
# File 'lib/split/experiment_catalog.rb', line 4 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
10 11 12 |
# File 'lib/split/experiment_catalog.rb', line 10 def self.all_active_first all.partition{|e| not e.winner}.map{|es| es.sort_by(&:name)}.flatten end |
.find(name) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/split/experiment_catalog.rb', line 14 def self.find(name) if Split.redis.exists(name) obj = Experiment.new name obj.load_from_redis else obj = nil end obj end |
.find_or_create(label, *alternatives) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/split/experiment_catalog.rb', line 24 def self.find_or_create(label, *alternatives) experiment_name_with_version, goals = normalize_experiment(label) name = experiment_name_with_version.to_s.split(':')[0] exp = Experiment.new name, :alternatives => alternatives, :goals => goals exp.save exp end |