Serialization and semi-permanent session-data storage class.
In order to create your own session store classes, you need to provide four methods: #insert, #update, #retrieve, #remove. All but one of the methods provides serialization and marking records as dirty in the base class, so unless you want to manage these tasks yourself, you should +super()+ to the parent‘s implementation with a block. Examples are provided for each method.
| #insert: | Insert a new session into the backing store. Example:
def insert
super {|data| @io.print(data) }
end
|
| #update: | Update an existing session‘s data in the backing store. Example:
def update
super {|data| @io.rewind; @io.truncate(0); @io.print(data) }
end
|
| #retrieve: | Retrieve the serialized session data from the backing store. Example:
def retrieve
super { @io.rewind; @io.read }
end
|
| #delete: | Delete the session from the backing store.
Example:
def delete
super {|data| @io.close; File.delete(@session_file) }
end
|
If you want to use something other than Marshal for object serialization, you can override the protected methods #serialized_data and #serialized_data= to provide your own serialization.
| #serialized_data: | Serialize the data in the instance variable +@data+ and return it. |
| #serialized_data=( serialized ): | Deserialize the given serialized data and assign it to @data. |
Example (serializing to YAML instead of binary):
require 'yaml'
def serialized_data
@data.to_yaml
end
def serialized_data=( data )
@data = YAML.load( data )
end
If arrow is configured to use the ‘recommended’ session lock, your session store can recommend one it knows will work (e.g., if your session store is a database, you can recommend a lock that uses database locking). The simple way to do that is to define a RecommendedLocker constant in your class which contains the URI of the locker you wish to use. If you need more control than the URI can provide, you can also override the #create_recommended_lock method, which should return an instance of the locker that should be used.
The method will be given the instantiated Arrow::Session::Id object that identifies the session so that you can derive a filename, primary key, etc.
Example:
def create_recommended_lock( idobj )
return DBITransactionLock.new( idobj.to_s )
end
Overridden factory method: handle a URI object or a name
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 142
142: def self::create( uri, idobj )
143: uri = Arrow::Session.parse_uri( uri ) if uri.is_a?( String )
144: super( uri.scheme.dup, uri, idobj )
145: end
Returns the Array of directories to search for derivatives; part of the PluginFactory interface.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 136
136: def self::derivativeDirs
137: [ 'arrow/session', 'arrow/session/store' ]
138: end
Create a new Arrow::Session::Store object.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 154
154: def initialize( uri, idobj )
155: @data = {}
156: @id = idobj
157: @new = true
158: @modified = false
159:
160: unless idobj.new?
161: self.retrieve
162: end
163:
164: super()
165: end
Set the value for the specified key.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 181
181: def []=( key, value )
182: @data[ key ] = value
183: @modified = true
184: end
Clear all key/value pairs from the store for this session.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 202
202: def clear
203: @data.clear
204: @modified = true
205: end
Returns an instance of the recommended lock object for the receiving store. If no recommended locking strategy is known, this method raises a SessionError.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 313
313: def create_recommended_lock( idobj )
314: self.log.debug "Searching for recommended lock for %s" %
315: self.class.name
316:
317: # Traverse the class hierarchy to find a class which defines a
318: # RecommendedLocker constant
319: adviceClass = self.class.ancestors.find {|klass|
320: klass.const_defined?( :RecommendedLocker )
321: } or raise SessionError, "No recommended locker for %p" %
322: self.class.ancestors
323:
324: uri = adviceClass.const_get( :RecommendedLocker ) or
325: raise SessionError, "Could not fetch RecommendedLocker constant"
326:
327: self.log.debug "Creating recommended lock %s" % uri
328: uri = Arrow::Session.parse_uri( uri ) if
329: uri.is_a?( String )
330:
331: lock = Arrow::Session::Lock.create( uri, idobj )
332: self.log.debug "Created recommended lock object: %p" % lock
333:
334: return lock
335: end
Deletes and returns a key-value pair from the receiver whose key is equal to key. If the key is not found, returns the default value. If the optional code-block is given and the key is not found, the block is called with the key, and the return value is used as the result of the method.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 193
193: def delete( key, &block )
194: rval = @data.delete( key, &block )
195: return rval
196: ensure
197: @modified = true if rval != @data.default
198: end
Insert the current data hash into whatever permanent storage the Store object is acting as an interface to. Concrete implementations should provide an overriding implementation of this method that calls #super with a block which will be called with the serialized data that should be stored.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 272
272: def insert
273: self.log.debug "Inserting session data for key %s" % @id
274: yield( self.serialized_data )
275: @new = @modified = false
276: end
Adds the contents of the other hash to the session data, overwriting entries in the session data with values from the other hash where there are duplicates. If a block is given, it is called for each duplicate key, and the return value is the value set in the hash.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 213
213: def merge!( other, &block ) # :yields: key, sessionValue, otherValue
214: @data.merge!( other, &block )
215: ensure
216: @modified = true
217: end
Returns true if the receiver‘s data is out of sync with the data in the backing store.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 243
243: def modified?
244: @modified
245: end
Deletes every key-value pair from the session data for which the block evaluates to true.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 232
232: def reject!( &block ) # :yields: key, value
233: rval = @data.reject!( &block )
234: return rval
235: ensure
236: @modified = true if rval
237: end
Permanently remove the data hash associated with the id used in the receiver‘s creation from permanent storage.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 304
304: def remove
305: self.log.debug "Removing session data for key %s" % @id
306: @new = true
307: end
Replace the contents of the session hash with those of the given other hash.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 223
223: def replace( other )
224: @data.replace( other )
225: ensure
226: @modified = true
227: end
Retrieve the data hash stored in permanent storage associated with the id the object was created with. Concrete implementations should provide an overriding implementation of this method that calls #super with a block that returns the serialized data to be restored.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 295
295: def retrieve
296: self.log.debug "Retrieving session data for key %s" % @id
297: self.serialized_data = yield
298: @new = @modified = false
299: end
Save the session data to the backing store
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 257
257: def save
258: return false unless self.modified? || self.new?
259: if self.new?
260: self.insert
261: else
262: self.update
263: end
264: end
Update the current data hash stored in permanent storage with the values contained in the store‘s data. Concrete implementations should provide an overriding implementation of this method that calls #super with a block which will be called with the serialized data that should be stored.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 284
284: def update
285: self.log.debug "Updating session data for key %s" % @id
286: yield( self.serialized_data )
287: @modified = false
288: end
Returns the data in the session store as a serialized object.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 343
343: def serialized_data
344: data = strip_hash( @data )
345: return Marshal.dump( data )
346: end
Sets the session‘s data by deserializing the object contained in the given string.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 351
351: def serialized_data=( string )
352: if string.empty?
353: self.log.error "No session data: retaining default hash"
354: else
355: @data = Marshal.restore( string )
356: end
357: end
--- SEC00119
--- ""
---
- name: data
rw: R
a_desc: |+
The raw session data hash
---
- methods:
- visibility: public
aref: M000084
name: create
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 142</span>\n\
142: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">create</span>( <span class=\"ruby-identifier\">uri</span>, <span class=\"ruby-identifier\">idobj</span> )\n\
143: <span class=\"ruby-identifier\">uri</span> = <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Session</span>.<span class=\"ruby-identifier\">parse_uri</span>( <span class=\"ruby-identifier\">uri</span> ) <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">uri</span>.<span class=\"ruby-identifier\">is_a?</span>( <span class=\"ruby-constant\">String</span> )\n\
144: <span class=\"ruby-keyword kw\">super</span>( <span class=\"ruby-identifier\">uri</span>.<span class=\"ruby-identifier\">scheme</span>.<span class=\"ruby-identifier\">dup</span>, <span class=\"ruby-identifier\">uri</span>, <span class=\"ruby-identifier\">idobj</span> )\n\
145: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Overridden factory method: handle a URI object or a name
</p>
params: ( uri, idobj )
- visibility: public
aref: M000083
name: derivativeDirs
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 136</span>\n\
136: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">derivativeDirs</span>\n\
137: [ <span class=\"ruby-value str\">'arrow/session'</span>, <span class=\"ruby-value str\">'arrow/session/store'</span> ]\n\
138: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Returns the Array of directories to search for derivatives; part of the
PluginFactory interface.
</p>
params: ()
- visibility: public
aref: M000085
name: new
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 154</span>\n\
154: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span>( <span class=\"ruby-identifier\">uri</span>, <span class=\"ruby-identifier\">idobj</span> )\n\
155: <span class=\"ruby-ivar\">@data</span> = {}\n\
156: <span class=\"ruby-ivar\">@id</span> = <span class=\"ruby-identifier\">idobj</span>\n\
157: <span class=\"ruby-ivar\">@new</span> = <span class=\"ruby-keyword kw\">true</span>\n\
158: <span class=\"ruby-ivar\">@modified</span> = <span class=\"ruby-keyword kw\">false</span>\n\
159: \n\
160: <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">idobj</span>.<span class=\"ruby-identifier\">new?</span>\n\
161: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">retrieve</span>\n\
162: <span class=\"ruby-keyword kw\">end</span>\n\
163: \n\
164: <span class=\"ruby-keyword kw\">super</span>()\n\
165: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Create a <a href="Store.html#M000085">new</a> <a
href="Store.html">Arrow::Session::Store</a> object.
</p>
params: ( uri, idobj )
category: Class
type: Public
- methods:
- visibility: public
aref: M000086
name: "[]="
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 181</span>\n\
181: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-operator\">[]=</span>( <span class=\"ruby-identifier\">key</span>, <span class=\"ruby-identifier\">value</span> )\n\
182: <span class=\"ruby-ivar\">@data</span>[ <span class=\"ruby-identifier\">key</span> ] = <span class=\"ruby-identifier\">value</span>\n\
183: <span class=\"ruby-ivar\">@modified</span> = <span class=\"ruby-keyword kw\">true</span>\n\
184: <span class=\"ruby-keyword kw\">end</span>"
aka:
- aref: Store.html#M000087
name: store
m_desc: |-
<p>
Set the <tt>value</tt> for the specified <tt>key</tt>.
</p>
params: ( key, value )
- visibility: public
aref: M000089
name: clear
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 202</span>\n\
202: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">clear</span>\n\
203: <span class=\"ruby-ivar\">@data</span>.<span class=\"ruby-identifier\">clear</span>\n\
204: <span class=\"ruby-ivar\">@modified</span> = <span class=\"ruby-keyword kw\">true</span>\n\
205: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Clear all key/value pairs from the <a href="Store.html#M000087">store</a>
for this session.
</p>
params: ()
- visibility: public
aref: M000102
name: create_recommended_lock
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 313</span>\n\
313: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">create_recommended_lock</span>( <span class=\"ruby-identifier\">idobj</span> )\n\
314: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">log</span>.<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">"Searching for recommended lock for %s"</span> <span class=\"ruby-operator\">%</span>\n\
315: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">class</span>.<span class=\"ruby-identifier\">name</span>\n\
316: \n\
317: <span class=\"ruby-comment cmt\"># Traverse the class hierarchy to find a class which defines a</span>\n\
318: <span class=\"ruby-comment cmt\"># RecommendedLocker constant</span>\n\
319: <span class=\"ruby-identifier\">adviceClass</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">class</span>.<span class=\"ruby-identifier\">ancestors</span>.<span class=\"ruby-identifier\">find</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">klass</span><span class=\"ruby-operator\">|</span>\n\
320: <span class=\"ruby-identifier\">klass</span>.<span class=\"ruby-identifier\">const_defined?</span>( <span class=\"ruby-identifier\">:RecommendedLocker</span> )\n\
321: } <span class=\"ruby-keyword kw\">or</span> <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">SessionError</span>, <span class=\"ruby-value str\">"No recommended locker for %p"</span> <span class=\"ruby-operator\">%</span>\n\
322: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">class</span>.<span class=\"ruby-identifier\">ancestors</span>\n\
323: \n\
324: <span class=\"ruby-identifier\">uri</span> = <span class=\"ruby-identifier\">adviceClass</span>.<span class=\"ruby-identifier\">const_get</span>( <span class=\"ruby-identifier\">:RecommendedLocker</span> ) <span class=\"ruby-keyword kw\">or</span>\n\
325: <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">SessionError</span>, <span class=\"ruby-value str\">"Could not fetch RecommendedLocker constant"</span>\n\
326: \n\
327: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">log</span>.<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">"Creating recommended lock %s"</span> <span class=\"ruby-operator\">%</span> <span class=\"ruby-identifier\">uri</span>\n\
328: <span class=\"ruby-identifier\">uri</span> = <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Session</span>.<span class=\"ruby-identifier\">parse_uri</span>( <span class=\"ruby-identifier\">uri</span> ) <span class=\"ruby-keyword kw\">if</span>\n\
329: <span class=\"ruby-identifier\">uri</span>.<span class=\"ruby-identifier\">is_a?</span>( <span class=\"ruby-constant\">String</span> )\n\
330: \n\
331: <span class=\"ruby-identifier\">lock</span> = <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Session</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Lock</span>.<span class=\"ruby-identifier\">create</span>( <span class=\"ruby-identifier\">uri</span>, <span class=\"ruby-identifier\">idobj</span> )\n\
332: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">log</span>.<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">"Created recommended lock object: %p"</span> <span class=\"ruby-operator\">%</span> <span class=\"ruby-identifier\">lock</span>\n\
333: \n\
334: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">lock</span>\n\
335: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Returns an instance of the recommended lock object for the receiving <a
href="Store.html#M000087">store</a>. If no recommended locking strategy is
known, this method raises a SessionError.
</p>
params: ( idobj )
- visibility: public
aref: M000088
name: delete
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 193</span>\n\
193: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">delete</span>( <span class=\"ruby-identifier\">key</span>, <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> )\n\
194: <span class=\"ruby-identifier\">rval</span> = <span class=\"ruby-ivar\">@data</span>.<span class=\"ruby-identifier\">delete</span>( <span class=\"ruby-identifier\">key</span>, <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> )\n\
195: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">rval</span>\n\
196: <span class=\"ruby-keyword kw\">ensure</span>\n\
197: <span class=\"ruby-ivar\">@modified</span> = <span class=\"ruby-keyword kw\">true</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">rval</span> <span class=\"ruby-operator\">!=</span> <span class=\"ruby-ivar\">@data</span>.<span class=\"ruby-identifier\">default</span>\n\
198: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Deletes and returns a key-value pair from the receiver whose key is equal
to <tt>key</tt>. If the <tt>key</tt> is not found, returns the default
value. If the optional code-block is given and the key is not found, the
block is called with the key, and the return value is used as the result of
the method.
</p>
params: ( key, &block )
- visibility: public
aref: M000094
name: delete_if
m_desc: |-
<p>
Alias for #reject!
</p>
params: ( )
- visibility: public
aref: M000098
name: insert
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 272</span>\n\
272: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">insert</span>\n\
273: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">log</span>.<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">"Inserting session data for key %s"</span> <span class=\"ruby-operator\">%</span> <span class=\"ruby-ivar\">@id</span>\n\
274: <span class=\"ruby-keyword kw\">yield</span>( <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">serialized_data</span> )\n\
275: <span class=\"ruby-ivar\">@new</span> = <span class=\"ruby-ivar\">@modified</span> = <span class=\"ruby-keyword kw\">false</span>\n\
276: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Insert the current <tt>data</tt> hash into whatever permanent storage the
<a href="Store.html">Store</a> object is acting as an interface to.
Concrete implementations should provide an overriding implementation of
this method that calls #super with a block which will be called with the
serialized data that should be stored.
</p>
params: () {|self.serialized_data| ...}
- visibility: public
aref: M000090
name: merge!
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 213</span>\n\
213: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">merge!</span>( <span class=\"ruby-identifier\">other</span>, <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> ) <span class=\"ruby-comment cmt\"># :yields: key, sessionValue, otherValue</span>\n\
214: <span class=\"ruby-ivar\">@data</span>.<span class=\"ruby-identifier\">merge!</span>( <span class=\"ruby-identifier\">other</span>, <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> )\n\
215: <span class=\"ruby-keyword kw\">ensure</span>\n\
216: <span class=\"ruby-ivar\">@modified</span> = <span class=\"ruby-keyword kw\">true</span>\n\
217: <span class=\"ruby-keyword kw\">end</span>"
aka:
- aref: Store.html#M000091
name: update
m_desc: |-
<p>
Adds the contents of the <tt>other</tt> hash to the session data,
overwriting entries in the session data with values from the <tt>other</tt>
hash where there are duplicates. If a <tt>block</tt> is given, it is called
for each duplicate key, and the return value is the value set in the hash.
</p>
params: ( other ) {|key, sessionValue, otherValue| ...}
- visibility: public
aref: M000095
name: modified?
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 243</span>\n\
243: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">modified?</span>\n\
244: <span class=\"ruby-ivar\">@modified</span>\n\
245: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Returns <tt>true</tt> if the receiver‘s data is out of sync with the
data in the backing <a href="Store.html#M000087">store</a>.
</p>
params: ()
- visibility: public
aref: M000096
name: new?
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 251</span>\n\
251: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">new?</span>\n\
252: <span class=\"ruby-ivar\">@new</span>\n\
253: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Returns <tt>true</tt> if the data in the receiver has not yet been saved to
the backing <a href="Store.html#M000087">store</a>, or if the entry in the
backing <a href="Store.html#M000087">store</a> has been deleted since it
was last saved.
</p>
params: ()
- visibility: public
aref: M000093
name: reject!
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 232</span>\n\
232: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">reject!</span>( <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> ) <span class=\"ruby-comment cmt\"># :yields: key, value</span>\n\
233: <span class=\"ruby-identifier\">rval</span> = <span class=\"ruby-ivar\">@data</span>.<span class=\"ruby-identifier\">reject!</span>( <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> )\n\
234: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">rval</span>\n\
235: <span class=\"ruby-keyword kw\">ensure</span>\n\
236: <span class=\"ruby-ivar\">@modified</span> = <span class=\"ruby-keyword kw\">true</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">rval</span>\n\
237: <span class=\"ruby-keyword kw\">end</span>"
aka:
- aref: Store.html#M000094
name: delete_if
m_desc: |-
<p>
Deletes every key-value pair from the session data for which the
<tt>block</tt> evaluates to true.
</p>
params: ( ) {|key, value| ...}
- visibility: public
aref: M000101
name: remove
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 304</span>\n\
304: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">remove</span>\n\
305: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">log</span>.<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">"Removing session data for key %s"</span> <span class=\"ruby-operator\">%</span> <span class=\"ruby-ivar\">@id</span>\n\
306: <span class=\"ruby-ivar\">@new</span> = <span class=\"ruby-keyword kw\">true</span>\n\
307: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Permanently <a href="Store.html#M000101">remove</a> the data hash
associated with the id used in the receiver‘s creation from permanent
storage.
</p>
params: ()
- visibility: public
aref: M000092
name: replace
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 223</span>\n\
223: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">replace</span>( <span class=\"ruby-identifier\">other</span> )\n\
224: <span class=\"ruby-ivar\">@data</span>.<span class=\"ruby-identifier\">replace</span>( <span class=\"ruby-identifier\">other</span> )\n\
225: <span class=\"ruby-keyword kw\">ensure</span>\n\
226: <span class=\"ruby-ivar\">@modified</span> = <span class=\"ruby-keyword kw\">true</span>\n\
227: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Replace the contents of the session hash with those of the given
<tt>other</tt> hash.
</p>
params: ( other )
- visibility: public
aref: M000100
name: retrieve
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 295</span>\n\
295: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">retrieve</span>\n\
296: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">log</span>.<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">"Retrieving session data for key %s"</span> <span class=\"ruby-operator\">%</span> <span class=\"ruby-ivar\">@id</span>\n\
297: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">serialized_data</span> = <span class=\"ruby-keyword kw\">yield</span>\n\
298: <span class=\"ruby-ivar\">@new</span> = <span class=\"ruby-ivar\">@modified</span> = <span class=\"ruby-keyword kw\">false</span>\n\
299: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Retrieve the data hash stored in permanent storage associated with the id
the object was created with. Concrete implementations should provide an
overriding implementation of this method that calls #super with a block
that returns the serialized data to be restored.
</p>
params: () {|| ...}
- visibility: public
aref: M000097
name: save
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 257</span>\n\
257: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">save</span>\n\
258: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">false</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">modified?</span> <span class=\"ruby-operator\">||</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">new?</span>\n\
259: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">new?</span>\n\
260: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">insert</span>\n\
261: <span class=\"ruby-keyword kw\">else</span>\n\
262: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">update</span>\n\
263: <span class=\"ruby-keyword kw\">end</span>\n\
264: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Save the session data to the backing <a href="Store.html#M000087">store</a>
</p>
params: ()
- visibility: public
aref: M000087
name: store
m_desc: |-
<p>
Alias for #[]=
</p>
params: ( key, value )
- visibility: public
aref: M000091
name: update
m_desc: |-
<p>
Alias for #merge!
</p>
params: ( other )
- visibility: public
aref: M000099
name: update
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 284</span>\n\
284: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">update</span>\n\
285: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">log</span>.<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">"Updating session data for key %s"</span> <span class=\"ruby-operator\">%</span> <span class=\"ruby-ivar\">@id</span>\n\
286: <span class=\"ruby-keyword kw\">yield</span>( <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">serialized_data</span> )\n\
287: <span class=\"ruby-ivar\">@modified</span> = <span class=\"ruby-keyword kw\">false</span>\n\
288: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Update the current data hash stored in permanent storage with the values
contained in the <a href="Store.html#M000087">store</a>‘s data.
Concrete implementations should provide an overriding implementation of
this method that calls #super with a block which will be called with the
serialized data that should be stored.
</p>
params: () {|self.serialized_data| ...}
category: Instance
type: Public
- methods:
- visibility: protected
aref: M000103
name: serialized_data
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 343</span>\n\
343: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">serialized_data</span>\n\
344: <span class=\"ruby-identifier\">data</span> = <span class=\"ruby-identifier\">strip_hash</span>( <span class=\"ruby-ivar\">@data</span> ) \n\
345: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-constant\">Marshal</span>.<span class=\"ruby-identifier\">dump</span>( <span class=\"ruby-identifier\">data</span> )\n\
346: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Returns the data in the session <a href="Store.html#M000087">store</a> as a
serialized object.
</p>
params: ()
- visibility: protected
aref: M000104
name: serialized_data=
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/store.rb, line 351</span>\n\
351: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">serialized_data=</span>( <span class=\"ruby-identifier\">string</span> )\n\
352: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">string</span>.<span class=\"ruby-identifier\">empty?</span>\n\
353: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">log</span>.<span class=\"ruby-identifier\">error</span> <span class=\"ruby-value str\">"No session data: retaining default hash"</span>\n\
354: <span class=\"ruby-keyword kw\">else</span>\n\
355: <span class=\"ruby-ivar\">@data</span> = <span class=\"ruby-constant\">Marshal</span>.<span class=\"ruby-identifier\">restore</span>( <span class=\"ruby-identifier\">string</span> )\n\
356: <span class=\"ruby-keyword kw\">end</span>\n\
357: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Sets the session‘s data by deserializing the object contained in the
given <tt>string</tt>.
</p>
params: ( string )
category: Instance
type: Protected
---
---
- name: SVNRev
desc: |+
SVN Revision
value: "%q$Rev: 439 $"
- name: SVNId
desc: |+
SVN <a href="Id.html">Id</a>
value: "%q$Id: store.rb 439 2008-04-10 23:27:34Z deveiant $"
- name: RecommendedLocker
desc: |+
The URI of the lock class recommended for use with this <a
href="Store.html">Store</a>.
value: URI.parse( 'file:.' )
- name: DelegatedMethods
desc: |+
The methods which are delegate directly to the data hash.
value: "[ :[], :default, :default=, :each, :each_key, :each_pair, :each_value, :empty?, :fetch, :has_key?, :has_value?, :include?, :index, :invert, :keys, :length, :member?, :merge, :rehash, :reject, :select, :size, :sort, :to_a, :value?, :values"
Generated with the Darkfish Rdoc Generator.