Module: Socrates::Storage::Storage

Included in:
Memory, Redis
Defined in:
lib/socrates/storage/storage.rb

Instance Method Summary collapse

Instance Method Details

#clear(key) ⇒ Object

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/socrates/storage/storage.rb', line 39

def clear(key)
  raise NotImplementedError
end

#clear_allObject

Raises:

  • (NotImplementedError)


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.message}"
    @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

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/socrates/storage/storage.rb', line 43

def get(key)
  raise NotImplementedError
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/socrates/storage/storage.rb', line 35

def has_key?(key)
  raise NotImplementedError
end

#initializeObject



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

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/socrates/storage/storage.rb', line 47

def put(key, value)
  raise NotImplementedError
end