Class: Split::Configuration
- Inherits:
-
Object
- Object
- Split::Configuration
- Defined in:
- lib/split/configuration.rb
Constant Summary collapse
- BOTS =
{ 'Baidu' => 'Chinese spider', 'Gigabot' => 'Gigabot spider', 'Googlebot' => 'Google spider', 'libwww-perl' => 'Perl client-server library loved by script kids', 'lwp-trivial' => 'Another Perl library loved by script kids', 'msnbot' => 'Microsoft bot', 'SiteUptime' => 'Site monitoring services', 'Slurp' => 'Yahoo spider', 'WordPress' => 'WordPress spider', 'ZIBB' => 'ZIBB spider', 'ZyBorg' => 'Zyborg? Hmmm....' }
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
Returns the value of attribute algorithm.
-
#allow_multiple_experiments ⇒ Object
Returns the value of attribute allow_multiple_experiments.
-
#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_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.
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.
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/split/configuration.rb', line 98 def initialize @robot_regex = /\b(#{BOTS.keys.join('|')})\b/i @ignore_ip_addresses = [] @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.
25 26 27 |
# File 'lib/split/configuration.rb', line 25 def algorithm @algorithm end |
#allow_multiple_experiments ⇒ Object
Returns the value of attribute allow_multiple_experiments.
21 22 23 |
# File 'lib/split/configuration.rb', line 21 def allow_multiple_experiments @allow_multiple_experiments end |
#db_failover ⇒ Object
Returns the value of attribute db_failover.
18 19 20 |
# File 'lib/split/configuration.rb', line 18 def db_failover @db_failover end |
#db_failover_allow_parameter_override ⇒ Object
Returns the value of attribute db_failover_allow_parameter_override.
20 21 22 |
# File 'lib/split/configuration.rb', line 20 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.
19 20 21 |
# File 'lib/split/configuration.rb', line 19 def db_failover_on_db_error @db_failover_on_db_error end |
#enabled ⇒ Object
Returns the value of attribute enabled.
22 23 24 |
# File 'lib/split/configuration.rb', line 22 def enabled @enabled end |
#experiments ⇒ Object
Returns the value of attribute experiments.
23 24 25 |
# File 'lib/split/configuration.rb', line 23 def experiments @experiments end |
#ignore_ip_addresses ⇒ Object
Returns the value of attribute ignore_ip_addresses.
17 18 19 |
# File 'lib/split/configuration.rb', line 17 def ignore_ip_addresses @ignore_ip_addresses end |
#persistence ⇒ Object
Returns the value of attribute persistence.
24 25 26 |
# File 'lib/split/configuration.rb', line 24 def persistence @persistence end |
#robot_regex ⇒ Object
Returns the value of attribute robot_regex.
16 17 18 |
# File 'lib/split/configuration.rb', line 16 def robot_regex @robot_regex end |
Instance Method Details
#disabled? ⇒ Boolean
27 28 29 |
# File 'lib/split/configuration.rb', line 27 def disabled? !enabled end |
#experiment_for(name) ⇒ Object
31 32 33 34 35 |
# File 'lib/split/configuration.rb', line 31 def experiment_for(name) if normalized_experiments normalized_experiments[name] end end |
#metrics ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/split/configuration.rb', line 37 def metrics return @metrics if defined?(@metrics) @metrics = {} if self.experiments self.experiments.each do |key, value| metric_name = value[:metric] if metric_name @metrics[metric_name] ||= [] @metrics[metric_name] << Split::Experiment.load_from_configuration(key) end end end @metrics end |
#normalize_alternatives(alternatives) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/split/configuration.rb', line 68 def normalize_alternatives(alternatives) given_probability, num_with_probability = alternatives.inject([0,0]) do |a,v| p, n = a if v.kind_of?(Hash) && v[:percent] [p + v[: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 v.kind_of?(Hash) && v[:name] && v[:percent] { v[:name] => v[:percent] / 100.0 } elsif v.kind_of?(Hash) && v[:name] { v[:name] => unassigned_probability } else { v => unassigned_probability } end end [alternatives.shift, alternatives] else alternatives = alternatives.dup [alternatives.shift, alternatives] end end |
#normalized_experiments ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/split/configuration.rb', line 52 def normalized_experiments if @experiments.nil? nil else experiment_config = {} @experiments.keys.each do | name | experiment_config[name] = {} end @experiments.each do | experiment_name, settings| experiment_config[experiment_name][:alternatives] = normalize_alternatives(settings[:alternatives]) if settings[:alternatives] end experiment_config end end |