Module: Socrates::Storage::Storage
Instance Method Summary collapse
- #clear(key) ⇒ Object
- #clear_all ⇒ Object
- #fetch(client_id) ⇒ Object
- #generate_key(client_id) ⇒ Object
- #get(key) ⇒ Object
- #has_key?(key) ⇒ Boolean
- #initialize ⇒ Object
- #persist(client_id, state_data) ⇒ Object
- #put(key, value) ⇒ Object
Instance Method Details
#clear(key) ⇒ Object
39 40 41 |
# File 'lib/socrates/storage/storage.rb', line 39 def clear(key) raise NotImplementedError end |
#clear_all ⇒ Object
51 52 53 |
# File 'lib/socrates/storage/storage.rb', line 51 def clear_all raise NotImplementedError end |
#fetch(client_id) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/socrates/storage/storage.rb', line 10 def fetch(client_id) key = generate_key(client_id) snapshot = get(key) return if snapshot.nil? begin Socrates::Core::StateData.deserialize(snapshot) rescue StandardError => e @logger.warn "Error while fetching state_data for client id '#{client_id}', resetting state: #{e.}" @logger.warn e end end |
#generate_key(client_id) ⇒ Object
31 32 33 |
# File 'lib/socrates/storage/storage.rb', line 31 def generate_key(client_id) client_id end |
#get(key) ⇒ Object
43 44 45 |
# File 'lib/socrates/storage/storage.rb', line 43 def get(key) raise NotImplementedError end |
#has_key?(key) ⇒ Boolean
35 36 37 |
# File 'lib/socrates/storage/storage.rb', line 35 def has_key?(key) raise NotImplementedError end |
#initialize ⇒ Object
6 7 8 |
# File 'lib/socrates/storage/storage.rb', line 6 def initialize @logger = Socrates.config.logger end |
#persist(client_id, state_data) ⇒ Object
25 26 27 28 29 |
# File 'lib/socrates/storage/storage.rb', line 25 def persist(client_id, state_data) key = generate_key(client_id) state_data.reset_elapsed_time put(key, state_data.serialize) end |
#put(key, value) ⇒ Object
47 48 49 |
# File 'lib/socrates/storage/storage.rb', line 47 def put(key, value) raise NotImplementedError end |