Class: Mongo::Session::ServerSession Private
- Inherits:
-
Object
- Object
- Mongo::Session::ServerSession
- Defined in:
- lib/mongo/session/server_session.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
An object representing the server-side session.
Constant Summary collapse
- DASH_REGEX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Regex for removing dashes from the UUID string.
/\-/.freeze
- UUID_PACK =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Pack directive for the UUID.
'H*'.freeze
Instance Attribute Summary collapse
-
#last_use ⇒ Object
readonly
private
The last time the server session was used.
-
#txn_num ⇒ Object
readonly
private
The current transactions number.
Instance Method Summary collapse
-
#initialize ⇒ ServerSession
constructor
private
Initialize a ServerSession.
-
#inspect ⇒ String
private
Get a formatted string for use in inspection.
-
#next_txn_num ⇒ Integer
private
Increment and return the next transaction number.
-
#session_id ⇒ BSON::Document
private
The session id of this server session.
-
#set_last_use! ⇒ Time
private
Update the last_use attribute of the server session to now.
Constructor Details
#initialize ⇒ ServerSession
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a ServerSession.
52 53 54 55 56 |
# File 'lib/mongo/session/server_session.rb', line 52 def initialize set_last_use! session_id @txn_num = 0 end |
Instance Attribute Details
#last_use ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The last time the server session was used.
39 40 41 |
# File 'lib/mongo/session/server_session.rb', line 39 def last_use @last_use end |
#txn_num ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The current transactions number.
44 45 46 |
# File 'lib/mongo/session/server_session.rb', line 44 def txn_num @txn_num end |
Instance Method Details
#inspect ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get a formatted string for use in inspection.
103 104 105 |
# File 'lib/mongo/session/server_session.rb', line 103 def inspect "#<Mongo::Session::ServerSession:0x#{object_id} session_id=#{session_id} last_use=#{@last_use}>" end |
#next_txn_num ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Increment and return the next transaction number.
91 92 93 |
# File 'lib/mongo/session/server_session.rb', line 91 def next_txn_num @txn_num += 1 end |
#session_id ⇒ BSON::Document
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The session id of this server session.
78 79 80 81 |
# File 'lib/mongo/session/server_session.rb', line 78 def session_id @session_id ||= (bytes = [SecureRandom.uuid.gsub(DASH_REGEX, '')].pack(UUID_PACK) BSON::Document.new(id: BSON::Binary.new(bytes, :uuid))) end |
#set_last_use! ⇒ Time
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Update the last_use attribute of the server session to now.
66 67 68 |
# File 'lib/mongo/session/server_session.rb', line 66 def set_last_use! @last_use = Time.now end |