Class: Arrow::Session::DbStore
- Inherits:
-
Store
- Object
- Arrow::Object
- Store
- Arrow::Session::DbStore
- Defined in:
- lib/arrow/session/dbstore.rb
Overview
The Arrow::Session::DbStore class, a derivative of Arrow::Session::Store. Instances of this class store a session object in a database.
Authors
Michael Granger
:include: LICENSE
—
Please see the file LICENSE in the BASE directory for licensing details.
Constant Summary
Constants inherited from Store
DelegatedMethods, RecommendedLocker
Instance Attribute Summary
-
- (Object) db
readonly
The database handle.
-
- (Object) id
readonly
The session ID this store was created for.
Instance Method Summary
-
- (DbStore) initialize(uri, idobj)
constructor
Create a new Arrow::Session::DbStore object.
-
- (Object) insert
Insert the specified data hash into whatever permanent storage the Store object is acting as an interface to.
-
- (Object) remove
Permanently remove the data hash associated with the id used in the receiver’s creation from permanent storage.
-
- (Object) retrieve
Retrieve the data hash stored in permanent storage associated with the id the object was created with.
-
- (Object) update
Update the current data hash stored in permanent storage with the values contained in data.
Methods inherited from Store
#[]=, #clear, create, #create_recommended_lock, derivativeDirs, #merge!, #modified?, #new?, #reject!, #replace, #save, #serialized_data, #serialized_data=
Methods inherited from Arrow::Object
deprecate_class_method, deprecate_method, inherited
Methods included from Arrow::Loggable
Constructor Details
- (DbStore) initialize(uri, idobj)
Create a new Arrow::Session::DbStore object.
29 30 31 32 33 34 35 |
# File 'lib/arrow/session/dbstore.rb', line 29 def initialize( uri, idobj ) db = Sequel.connect( uri ) dataset = db[] @id = idobj super end |
Instance Attribute Details
- (Object) db (readonly)
The database handle
43 44 45 |
# File 'lib/arrow/session/dbstore.rb', line 43 def db @db end |
- (Object) id (readonly)
The session ID this store was created for
46 47 48 |
# File 'lib/arrow/session/dbstore.rb', line 46 def id @id end |
Instance Method Details
- (Object) insert
Insert the specified data hash into whatever permanent storage the Store object is acting as an interface to.
51 52 53 54 55 56 |
# File 'lib/arrow/session/dbstore.rb', line 51 def insert super {|data| self.log.debug "Inserting data into session table for session %s" % [ self.id ] self. } end |
- (Object) remove
Permanently remove the data hash associated with the id used in the receiver’s creation from permanent storage.
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/arrow/session/dbstore.rb', line 85 def remove super self.close file = self.session_file if File.exists?( file ) File.delete( file ) else raise Arrow::SessionError, "Session file #{file} does not exist in the data store" end end |
- (Object) retrieve
Retrieve the data hash stored in permanent storage associated with the id the object was created with.
73 74 75 76 77 78 79 80 |
# File 'lib/arrow/session/dbstore.rb', line 73 def retrieve super { self.log.debug "Reading data in session file" ofh = self.open( File::RDWR ) ofh.seek( 0, File::SEEK_SET ) ofh.read } end |
- (Object) update
Update the current data hash stored in permanent storage with the values contained in data.
61 62 63 64 65 66 67 68 |
# File 'lib/arrow/session/dbstore.rb', line 61 def update super {|data| self.log.debug "Updating data in session file" ofh = self.open ofh.seek( 0, File::SEEK_SET ) ofh.print( data ) } end |