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.



21
22
23
# File 'lib/aws/session_store/dynamo_db/locking/base.rb', line 21

def initialize(cfg)
  @config = cfg
end

Instance Method Details

#delete_session(env, sid) ⇒ Object

Deletes session based on id



47
48
49
50
51
# File 'lib/aws/session_store/dynamo_db/locking/base.rb', line 47

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)


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

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.



56
57
58
59
60
61
62
# File 'lib/aws/session_store/dynamo_db/locking/base.rb', line 56

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

#pack_data(data) ⇒ Object

Packs session data.



37
38
39
# File 'lib/aws/session_store/dynamo_db/locking/base.rb', line 37

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

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

Updates session in database



26
27
28
29
30
31
32
33
34
# File 'lib/aws/session_store/dynamo_db/locking/base.rb', line 26

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)
    result = @config.dynamo_db_client.update_item(save_opts)
    sid
  end
end