Class: Aws::SessionStore::DynamoDB::Locking::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/session_store/dynamo_db/locking/base.rb

Overview

This class provides a framework for implementing locking strategies.

Direct Known Subclasses

Null, Pessimistic

Instance Method Summary collapse

Constructor Details

#initialize(cfg) ⇒ Base

Creates configuration object.



7
8
9
# File 'lib/aws/session_store/dynamo_db/locking/base.rb', line 7

def initialize(cfg)
  @config = cfg
end

Instance Method Details

#delete_session(env, sid) ⇒ Object

Deletes session based on id



33
34
35
36
37
# File 'lib/aws/session_store/dynamo_db/locking/base.rb', line 33

def delete_session(env, sid)
  handle_error(env) do
    @config.dynamo_db_client.delete_item(delete_opts(sid))
  end
end

#get_session_data(env, sid) ⇒ Object

Gets session data.

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/aws/session_store/dynamo_db/locking/base.rb', line 28

def get_session_data(env, sid)
  raise NotImplementedError
end

#handle_error(env = nil, &block) ⇒ Object

Each database operation is placed in this rescue wrapper. This wrapper will call the method, rescue any exceptions and then pass exceptions to the configured error handler.



42
43
44
45
46
47
48
# File 'lib/aws/session_store/dynamo_db/locking/base.rb', line 42

def handle_error(env = nil, &block)
  begin
    yield
  rescue Aws::DynamoDB::Errors::ServiceError => e
    @config.error_handler.handle_error(e, env)
  end
end

#pack_data(data) ⇒ Object

Packs session data.



23
24
25
# File 'lib/aws/session_store/dynamo_db/locking/base.rb', line 23

def pack_data(data)
  [Marshal.dump(data)].pack("m*")
end

#set_session_data(env, sid, session, options = {}) ⇒ Object

Updates session in database



12
13
14
15
16
17
18
19
20
# File 'lib/aws/session_store/dynamo_db/locking/base.rb', line 12

def set_session_data(env, sid, session, options = {})
  return false if session.empty?
  packed_session = pack_data(session)
  handle_error(env) do
    save_opts = update_opts(env, sid, packed_session, options)
    @config.dynamo_db_client.update_item(save_opts)
    sid
  end
end