Class: Split::Configuration
- Inherits:
-
Object
- Object
- Split::Configuration
- Defined in:
- lib/split/configuration.rb
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
Returns the value of attribute algorithm.
-
#allow_multiple_experiments ⇒ Object
Returns the value of attribute allow_multiple_experiments.
-
#bots ⇒ Object
Returns the value of attribute bots.
-
#db_failover ⇒ Object
Returns the value of attribute db_failover.
-
#db_failover_allow_parameter_override ⇒ Object
Returns the value of attribute db_failover_allow_parameter_override.
-
#db_failover_on_db_error ⇒ Object
Returns the value of attribute db_failover_on_db_error.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#experiments ⇒ Object
Returns the value of attribute experiments.
-
#ignore_filter ⇒ Object
Returns the value of attribute ignore_filter.
-
#ignore_ip_addresses ⇒ Object
Returns the value of attribute ignore_ip_addresses.
-
#persistence ⇒ Object
Returns the value of attribute persistence.
-
#robot_regex ⇒ Object
Returns the value of attribute robot_regex.
-
#store_override ⇒ Object
Returns the value of attribute store_override.
Instance Method Summary collapse
- #disabled? ⇒ Boolean
- #experiment_for(name) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #metrics ⇒ Object
- #normalize_alternatives(alternatives) ⇒ Object
- #normalized_experiments ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/split/configuration.rb', line 157 def initialize @ignore_ip_addresses = [] @ignore_filter = proc{ |request| is_robot? || is_ignored_ip_address? } @db_failover = false @db_failover_on_db_error = proc{|error|} # e.g. use Rails logger here @db_failover_allow_parameter_override = false @allow_multiple_experiments = false @enabled = true @experiments = {} @persistence = Split::Persistence::SessionAdapter @algorithm = Split::Algorithms::WeightedSample end |
Instance Attribute Details
#algorithm ⇒ Object
Returns the value of attribute algorithm.
13 14 15 |
# File 'lib/split/configuration.rb', line 13 def algorithm @algorithm end |
#allow_multiple_experiments ⇒ Object
Returns the value of attribute allow_multiple_experiments.
10 11 12 |
# File 'lib/split/configuration.rb', line 10 def allow_multiple_experiments @allow_multiple_experiments end |
#bots ⇒ Object
Returns the value of attribute bots.
3 4 5 |
# File 'lib/split/configuration.rb', line 3 def bots @bots end |
#db_failover ⇒ Object
Returns the value of attribute db_failover.
7 8 9 |
# File 'lib/split/configuration.rb', line 7 def db_failover @db_failover end |
#db_failover_allow_parameter_override ⇒ Object
Returns the value of attribute db_failover_allow_parameter_override.
9 10 11 |
# File 'lib/split/configuration.rb', line 9 def db_failover_allow_parameter_override @db_failover_allow_parameter_override end |
#db_failover_on_db_error ⇒ Object
Returns the value of attribute db_failover_on_db_error.
8 9 10 |
# File 'lib/split/configuration.rb', line 8 def db_failover_on_db_error @db_failover_on_db_error end |
#enabled ⇒ Object
Returns the value of attribute enabled.
11 12 13 |
# File 'lib/split/configuration.rb', line 11 def enabled @enabled end |
#experiments ⇒ Object
Returns the value of attribute experiments.
16 17 18 |
# File 'lib/split/configuration.rb', line 16 def experiments @experiments end |
#ignore_filter ⇒ Object
Returns the value of attribute ignore_filter.
6 7 8 |
# File 'lib/split/configuration.rb', line 6 def ignore_filter @ignore_filter end |
#ignore_ip_addresses ⇒ Object
Returns the value of attribute ignore_ip_addresses.
5 6 7 |
# File 'lib/split/configuration.rb', line 5 def ignore_ip_addresses @ignore_ip_addresses end |
#persistence ⇒ Object
Returns the value of attribute persistence.
12 13 14 |
# File 'lib/split/configuration.rb', line 12 def persistence @persistence end |
#robot_regex ⇒ Object
Returns the value of attribute robot_regex.
4 5 6 |
# File 'lib/split/configuration.rb', line 4 def robot_regex @robot_regex end |
#store_override ⇒ Object
Returns the value of attribute store_override.
14 15 16 |
# File 'lib/split/configuration.rb', line 14 def store_override @store_override end |
Instance Method Details
#disabled? ⇒ Boolean
73 74 75 |
# File 'lib/split/configuration.rb', line 73 def disabled? !enabled end |
#experiment_for(name) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/split/configuration.rb', line 77 def experiment_for(name) if normalized_experiments # TODO symbols normalized_experiments[name.to_sym] end end |
#metrics ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/split/configuration.rb', line 84 def metrics return @metrics if defined?(@metrics) @metrics = {} if self.experiments self.experiments.each do |key, value| metric_name = value_for(value, :metric).to_sym rescue nil if metric_name @metrics[metric_name] ||= [] @metrics[metric_name] << Split::Experiment.new(key) end end end @metrics end |
#normalize_alternatives(alternatives) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/split/configuration.rb', line 122 def normalize_alternatives(alternatives) given_probability, num_with_probability = alternatives.inject([0,0]) do |a,v| p, n = a if percent = value_for(v, :percent) [p + percent, n + 1] else a end end num_without_probability = alternatives.length - num_with_probability unassigned_probability = ((100.0 - given_probability) / num_without_probability / 100.0) if num_with_probability.nonzero? alternatives = alternatives.map do |v| if (name = value_for(v, :name)) && (percent = value_for(v, :percent)) { name => percent / 100.0 } elsif name = value_for(v, :name) { name => unassigned_probability } else { v => unassigned_probability } end end [alternatives.shift, alternatives] else alternatives = alternatives.dup [alternatives.shift, alternatives] end end |
#normalized_experiments ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/split/configuration.rb', line 99 def normalized_experiments if @experiments.nil? nil else experiment_config = {} @experiments.keys.each do |name| experiment_config[name.to_sym] = {} end @experiments.each do |experiment_name, settings| if alternatives = value_for(settings, :alternatives) experiment_config[experiment_name.to_sym][:alternatives] = normalize_alternatives(alternatives) end if goals = value_for(settings, :goals) experiment_config[experiment_name.to_sym][:goals] = goals end end experiment_config end end |