Class: Verdict::Storage::CookieStorage
- Inherits:
-
BaseStorage
- Object
- BaseStorage
- Verdict::Storage::CookieStorage
- Defined in:
- lib/verdict/storage/cookie_storage.rb
Overview
CookieStorage, unlike other Verdict storage classes, is distributed and stored on the client. Because cookies are opaque to users, we obsfucate information about the test such as the human readable names for the experiment or assignment group. This means this class assumes that ‘name` will be an obsfucated value, or one that we comfortable being “public”.
Constant Summary collapse
- DEFAULT_COOKIE_LIFESPAN_SECONDS =
6 months
15778476
- KEY =
:assignment
Instance Attribute Summary collapse
-
#cookie_lifespan ⇒ Object
readonly
Returns the value of attribute cookie_lifespan.
-
#cookies ⇒ Object
Returns the value of attribute cookies.
Instance Method Summary collapse
-
#initialize(cookie_lifespan: DEFAULT_COOKIE_LIFESPAN_SECONDS) ⇒ CookieStorage
constructor
A new instance of CookieStorage.
- #remove_assignment(experiment, _subject) ⇒ Object
- #retrieve_assignment(experiment, subject) ⇒ Object
- #retrieve_start_timestamp(_experiment) ⇒ Object
- #store_assignment(assignment) ⇒ Object
- #store_start_timestamp(_experiment, _timestamp) ⇒ Object
Methods inherited from BaseStorage
Constructor Details
#initialize(cookie_lifespan: DEFAULT_COOKIE_LIFESPAN_SECONDS) ⇒ CookieStorage
Returns a new instance of CookieStorage.
16 17 18 19 |
# File 'lib/verdict/storage/cookie_storage.rb', line 16 def initialize(cookie_lifespan: DEFAULT_COOKIE_LIFESPAN_SECONDS) @cookies = nil @cookie_lifespan = end |
Instance Attribute Details
#cookie_lifespan ⇒ Object (readonly)
Returns the value of attribute cookie_lifespan.
14 15 16 |
# File 'lib/verdict/storage/cookie_storage.rb', line 14 def @cookie_lifespan end |
#cookies ⇒ Object
Returns the value of attribute cookies.
13 14 15 |
# File 'lib/verdict/storage/cookie_storage.rb', line 13 def @cookies end |
Instance Method Details
#remove_assignment(experiment, _subject) ⇒ Object
44 45 46 |
# File 'lib/verdict/storage/cookie_storage.rb', line 44 def remove_assignment(experiment, _subject) remove(experiment.handle.to_s, KEY) end |
#retrieve_assignment(experiment, subject) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/verdict/storage/cookie_storage.rb', line 30 def retrieve_assignment(experiment, subject) if (value = get(experiment.handle.to_s, KEY)) data = (value) group = find_group_by_digest(experiment, data['group']) if group.nil? experiment.remove_subject_assignment(subject) return nil end experiment.subject_assignment(subject, group, Time.xmlschema(data['created_at'])) end end |
#retrieve_start_timestamp(_experiment) ⇒ Object
48 49 50 |
# File 'lib/verdict/storage/cookie_storage.rb', line 48 def (_experiment) nil end |
#store_assignment(assignment) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/verdict/storage/cookie_storage.rb', line 21 def store_assignment(assignment) data = { group: digest_of(assignment.group.to_s), created_at: assignment.created_at.strftime('%FT%TZ') } set(assignment.experiment.handle.to_s, KEY, JSON.dump(data)) end |
#store_start_timestamp(_experiment, _timestamp) ⇒ Object
52 53 54 |
# File 'lib/verdict/storage/cookie_storage.rb', line 52 def (_experiment, ) raise NotImplementedError end |