Class: Split::User
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #active_experiments ⇒ Object
- #cleanup_old_experiments! ⇒ 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.
11 12 13 14 |
# File 'lib/split/user.rb', line 11 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.
9 10 11 |
# File 'lib/split/user.rb', line 9 def user @user end |
Class Method Details
.find(user_id, adapter) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/split/user.rb', line 57 def self.find(user_id, adapter) adapter = adapter.is_a?(Symbol) ? Split::Persistence::ADAPTERS[adapter] : adapter if adapter.respond_to?(:find) User.new(nil, adapter.find(user_id)) else nil end end |
Instance Method Details
#active_experiments ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/split/user.rb', line 45 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! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/split/user.rb', line 16 def cleanup_old_experiments! return if @cleaned_up keys_without_finished(user.keys).each do |key| experiment = ExperimentCatalog.find 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
40 41 42 43 |
# File 'lib/split/user.rb', line 40 def cleanup_old_versions!(experiment) keys = user.keys.select { |k| key_without_version(k) == experiment.name } keys_without_experiment(keys, experiment.key).each { |key| user.delete(key) } end |
#max_experiments_reached?(experiment_key) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/split/user.rb', line 28 def max_experiments_reached?(experiment_key) if Split.configuration.allow_multiple_experiments == "control" experiments = active_experiments experiment_key_without_version = key_without_version(experiment_key) count_control = experiments.count { |k, v| k == experiment_key_without_version || v == "control" } experiments.size > count_control else !Split.configuration.allow_multiple_experiments && keys_without_experiment(user.keys, experiment_key).length > 0 end end |