Class: Split::User
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #active_experiments ⇒ Object
- #cleanup_old_experiments!(experiment) ⇒ Object
- #cleanup_old_versions!(experiment) ⇒ Object
-
#initialize(context, adapter = nil) ⇒ User
constructor
A new instance of User.
- #max_experiments_reached?(experiment_key) ⇒ Boolean
Constructor Details
#initialize(context, adapter = nil) ⇒ User
Returns a new instance of User.
10 11 12 13 |
# File 'lib/split/user.rb', line 10 def initialize(context, adapter=nil) @user = adapter || Split::Persistence.adapter.new(context) @cleaned_up = false end |
Instance Attribute Details
#user ⇒ Object (readonly)
Returns the value of attribute user.
8 9 10 |
# File 'lib/split/user.rb', line 8 def user @user end |
Instance Method Details
#active_experiments ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/split/user.rb', line 43 def active_experiments experiment_pairs = {} keys_without_finished(user.keys).each do |key| Metric.possible_experiments(key_without_version(key)).each do |experiment| if !experiment.has_winner? experiment_pairs[key_without_version(key)] = user[key] end end end experiment_pairs end |
#cleanup_old_experiments!(experiment) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/split/user.rb', line 15 def cleanup_old_experiments! experiment return if @cleaned_up keys_without_finished(user.keys).each do |key| return unless experiment.name == key_without_version(key) if experiment.nil? || experiment.has_winner? || experiment.start_time.nil? user.delete key user.delete Experiment.finished_key(key) end end @cleaned_up = true end |
#cleanup_old_versions!(experiment) ⇒ Object
38 39 40 41 |
# File 'lib/split/user.rb', line 38 def cleanup_old_versions!(experiment) keys = user.keys.select { |k| k.match(Regexp.new(experiment.name)) } keys_without_experiment(keys, experiment.key).each { |key| user.delete(key) } end |
#max_experiments_reached?(experiment_key) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/split/user.rb', line 27 def max_experiments_reached?(experiment_key) if Split.configuration.allow_multiple_experiments == 'control' experiments = active_experiments count_control = experiments.count {|k,v| k == experiment_key || v == 'control'} experiments.size > count_control else !Split.configuration.allow_multiple_experiments && keys_without_experiment(user.keys, experiment_key).length > 0 end end |