Class: Verdict::Storage::BaseStorage
- Inherits:
-
Object
- Object
- Verdict::Storage::BaseStorage
- Defined in:
- lib/verdict/storage/base_storage.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#cleanup(experiment_or_scope, options = {}) ⇒ Object
Deletes all assignments (and any other stored data) for the given experiment.
-
#remove_assignment(experiment, subject) ⇒ Object
Should remove the subject from storage, so it will be reassigned later.
-
#retrieve_assignment(experiment, subject) ⇒ Object
Should do a fast lookup of an assignment of the subject for the given experiment.
-
#retrieve_start_timestamp(experiment) ⇒ Object
Retrieves the start timestamp of the experiment.
-
#store_assignment(assignment) ⇒ Object
Should store the assignments to allow quick lookups.
-
#store_start_timestamp(experiment, timestamp) ⇒ Object
Stores the timestamp on which the experiment was started.
Instance Method Details
#cleanup(experiment_or_scope, options = {}) ⇒ Object
Deletes all assignments (and any other stored data) for the given experiment
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/verdict/storage/base_storage.rb', line 49 def cleanup(experiment_or_scope, = {}) if experiment_or_scope.is_a?(Symbol) || experiment_or_scope.is_a?(String) Verdict.default_logger.warn( "Passing a scope string/symbol to #{self.class}#cleanup is deprecated, " \ 'pass a Verdict::Experiment instance instead.' ) clear(experiment_or_scope, ) else clear(experiment_or_scope.handle.to_s, ) end end |
#remove_assignment(experiment, subject) ⇒ Object
Should remove the subject from storage, so it will be reassigned later.
31 32 33 34 |
# File 'lib/verdict/storage/base_storage.rb', line 31 def remove_assignment(experiment, subject) subject_identifier = experiment.retrieve_subject_identifier(subject) remove(experiment.handle.to_s, "assignment_#{subject_identifier}") end |
#retrieve_assignment(experiment, subject) ⇒ Object
Should do a fast lookup of an assignment of the subject for the given experiment.
-
Should return nil if not found in store
-
Should return an Assignment instance otherwise.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/verdict/storage/base_storage.rb', line 18 def retrieve_assignment(experiment, subject) subject_identifier = experiment.retrieve_subject_identifier(subject) if value = get(experiment.handle.to_s, "assignment_#{subject_identifier}") hash = JSON.parse(value) experiment.subject_assignment( subject, experiment.group(hash['group']), Time.xmlschema(hash['created_at']) ) end end |
#retrieve_start_timestamp(experiment) ⇒ Object
Retrieves the start timestamp of the experiment
37 38 39 40 41 |
# File 'lib/verdict/storage/base_storage.rb', line 37 def (experiment) if = get(experiment.handle.to_s, 'started_at') Time.parse() end end |
#store_assignment(assignment) ⇒ Object
Should store the assignments to allow quick lookups.
-
Assignments should be unique on the combination of ‘assignment.experiment.handle` and `assignment.subject_identifier`.
-
The main property to store is ‘group.handle`
-
Should return true if stored successfully.
10 11 12 13 |
# File 'lib/verdict/storage/base_storage.rb', line 10 def store_assignment(assignment) hash = { group: assignment.handle, created_at: assignment.created_at.strftime('%FT%TZ') } set(assignment.experiment.handle.to_s, "assignment_#{assignment.subject_identifier}", JSON.dump(hash)) end |
#store_start_timestamp(experiment, timestamp) ⇒ Object
Stores the timestamp on which the experiment was started
44 45 46 |
# File 'lib/verdict/storage/base_storage.rb', line 44 def (experiment, ) set(experiment.handle.to_s, 'started_at', .utc.strftime('%FT%TZ')) end |