Instances of this class store a session object as a marshalled hash on disk.
Create a new Arrow::Session::FileStore object.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 45
45: def initialize( uri, idobj )
46: path = (uri.path || uri.opaque).dup
47: path.untaint
48:
49: @dir = File.expand_path( path )
50: @io = nil
51:
52: super
53: end
Close the output filehandle if it is opened.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 94
94: def close
95: @io.close unless @io.nil? || @io.closed?
96: end
Insert the specified data hash into whatever permanent storage the Store object is acting as an interface to.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 101
101: def insert
102: super {|data|
103: self.log.debug "Inserting data into session file"
104: self.open( DefaultIoFlags|File::EXCL ).print( data )
105: }
106: end
Get the output filehandle for the session backing store file. Open it with the specified ioflags if it‘s not already open.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 81
81: def open( ioflags=DefaultIoFlags )
82: if @io.nil? || @io.closed?
83: file = self.session_file
84: self.log.debug "Opening session file %s" % file
85: @io = File.open( file, File::RDWR|File::CREAT )
86: @io.sync = true
87: end
88:
89: return @io
90: 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/filestore.rb, line 135
135: def remove
136: super
137: self.close
138: file = self.session_file
139: if File.exists?( file )
140: File.delete( file )
141: else
142: raise Arrow::SessionError,
143: "Session file #{file} does not exist in the data store"
144: end
145: end
Retrieve the data hash stored in permanent storage associated with the id the object was created with.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 123
123: def retrieve
124: super {
125: self.log.debug "Reading data in session file"
126: ofh = self.open( File::RDWR )
127: ofh.seek( 0, File::SEEK_SET )
128: ofh.read
129: }
130: end
Close the file after saving to make sure it‘s synched.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 72
72: def save
73: super
74: @io = nil
75: end
Return the fully-qualified path to the session file for this store.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 66
66: def session_file
67: return File.join( @dir, @id.to_s )
68: end
Update the current data hash stored in permanent storage with the values contained in data.
# File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 111
111: def update
112: super {|data|
113: self.log.debug "Updating data in session file"
114: ofh = self.open
115: ofh.seek( 0, File::SEEK_SET )
116: ofh.print( data )
117: }
118: end
--- SEC00105
--- ""
---
- name: dir
rw: R
a_desc: |+
The fully-qualified directory in which session files will be written.
---
- methods:
- visibility: public
aref: M000112
name: new
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 45</span>\n\
45: <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\
46: <span class=\"ruby-identifier\">path</span> = (<span class=\"ruby-identifier\">uri</span>.<span class=\"ruby-identifier\">path</span> <span class=\"ruby-operator\">||</span> <span class=\"ruby-identifier\">uri</span>.<span class=\"ruby-identifier\">opaque</span>).<span class=\"ruby-identifier\">dup</span>\n\
47: <span class=\"ruby-identifier\">path</span>.<span class=\"ruby-identifier\">untaint</span>\n\
48: \n\
49: <span class=\"ruby-ivar\">@dir</span> = <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">expand_path</span>( <span class=\"ruby-identifier\">path</span> )\n\
50: <span class=\"ruby-ivar\">@io</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
51: \n\
52: <span class=\"ruby-keyword kw\">super</span>\n\
53: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Create a <a href="FileStore.html#M000112">new</a> <a
href="FileStore.html">Arrow::Session::FileStore</a> object.
</p>
params: ( uri, idobj )
category: Class
type: Public
- methods:
- visibility: public
aref: M000116
name: close
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 94</span>\n\
94: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">close</span>\n\
95: <span class=\"ruby-ivar\">@io</span>.<span class=\"ruby-identifier\">close</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-ivar\">@io</span>.<span class=\"ruby-identifier\">nil?</span> <span class=\"ruby-operator\">||</span> <span class=\"ruby-ivar\">@io</span>.<span class=\"ruby-identifier\">closed?</span>\n\
96: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Close the output filehandle if it is opened.
</p>
params: ()
- visibility: public
aref: M000117
name: insert
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 101</span>\n\
101: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">insert</span>\n\
102: <span class=\"ruby-keyword kw\">super</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">data</span><span class=\"ruby-operator\">|</span>\n\
103: <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 data into session file"</span>\n\
104: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">open</span>( <span class=\"ruby-constant\">DefaultIoFlags</span><span class=\"ruby-operator\">|</span><span class=\"ruby-constant\">File</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">EXCL</span> ).<span class=\"ruby-identifier\">print</span>( <span class=\"ruby-identifier\">data</span> )\n\
105: }\n\
106: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Insert the specified <tt>data</tt> hash into whatever permanent storage the
<a href="Store.html">Store</a> object is acting as an interface to.
</p>
params: ()
- visibility: public
aref: M000115
name: open
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 81</span>\n\
81: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">open</span>( <span class=\"ruby-identifier\">ioflags</span>=<span class=\"ruby-constant\">DefaultIoFlags</span> )\n\
82: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@io</span>.<span class=\"ruby-identifier\">nil?</span> <span class=\"ruby-operator\">||</span> <span class=\"ruby-ivar\">@io</span>.<span class=\"ruby-identifier\">closed?</span>\n\
83: <span class=\"ruby-identifier\">file</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">session_file</span>\n\
84: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">log</span>.<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">"Opening session file %s"</span> <span class=\"ruby-operator\">%</span> <span class=\"ruby-identifier\">file</span>\n\
85: <span class=\"ruby-ivar\">@io</span> = <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">open</span>( <span class=\"ruby-identifier\">file</span>, <span class=\"ruby-constant\">File</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">RDWR</span><span class=\"ruby-operator\">|</span><span class=\"ruby-constant\">File</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">CREAT</span> )\n\
86: <span class=\"ruby-ivar\">@io</span>.<span class=\"ruby-identifier\">sync</span> = <span class=\"ruby-keyword kw\">true</span>\n\
87: <span class=\"ruby-keyword kw\">end</span>\n\
88: \n\
89: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-ivar\">@io</span>\n\
90: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Get the output filehandle for the session backing store file. Open it with
the specified <tt>ioflags</tt> if it‘s not already <a
href="FileStore.html#M000115">open</a>.
</p>
params: ( ioflags=DefaultIoFlags )
- visibility: public
aref: M000120
name: remove
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 135</span>\n\
135: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">remove</span>\n\
136: <span class=\"ruby-keyword kw\">super</span>\n\
137: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">close</span>\n\
138: <span class=\"ruby-identifier\">file</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">session_file</span>\n\
139: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">exists?</span>( <span class=\"ruby-identifier\">file</span> )\n\
140: <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">delete</span>( <span class=\"ruby-identifier\">file</span> )\n\
141: <span class=\"ruby-keyword kw\">else</span>\n\
142: <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">SessionError</span>,\n\
143: <span class=\"ruby-node\">"Session file #{file} does not exist in the data store"</span>\n\
144: <span class=\"ruby-keyword kw\">end</span>\n\
145: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Permanently <a href="FileStore.html#M000120">remove</a> the data hash
associated with the id used in the receiver‘s creation from permanent
storage.
</p>
params: ()
- visibility: public
aref: M000119
name: retrieve
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 123</span>\n\
123: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">retrieve</span>\n\
124: <span class=\"ruby-keyword kw\">super</span> {\n\
125: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">log</span>.<span class=\"ruby-identifier\">debug</span> <span class=\"ruby-value str\">"Reading data in session file"</span>\n\
126: <span class=\"ruby-identifier\">ofh</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">open</span>( <span class=\"ruby-constant\">File</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">RDWR</span> )\n\
127: <span class=\"ruby-identifier\">ofh</span>.<span class=\"ruby-identifier\">seek</span>( <span class=\"ruby-value\">0</span>, <span class=\"ruby-constant\">File</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">SEEK_SET</span> )\n\
128: <span class=\"ruby-identifier\">ofh</span>.<span class=\"ruby-identifier\">read</span>\n\
129: }\n\
130: <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.
</p>
params: ()
- visibility: public
aref: M000114
name: save
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 72</span>\n\
72: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">save</span>\n\
73: <span class=\"ruby-keyword kw\">super</span>\n\
74: <span class=\"ruby-ivar\">@io</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
75: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Close the file after saving to make sure it‘s synched.
</p>
params: ()
- visibility: public
aref: M000113
name: session_file
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 66</span>\n\
66: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">session_file</span>\n\
67: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">join</span>( <span class=\"ruby-ivar\">@dir</span>, <span class=\"ruby-ivar\">@id</span>.<span class=\"ruby-identifier\">to_s</span> )\n\
68: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Return the fully-qualified path to the session file for this store.
</p>
params: ()
- visibility: public
aref: M000118
name: update
sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/session/filestore.rb, line 111</span>\n\
111: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">update</span>\n\
112: <span class=\"ruby-keyword kw\">super</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">data</span><span class=\"ruby-operator\">|</span>\n\
113: <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 data in session file"</span>\n\
114: <span class=\"ruby-identifier\">ofh</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">open</span>\n\
115: <span class=\"ruby-identifier\">ofh</span>.<span class=\"ruby-identifier\">seek</span>( <span class=\"ruby-value\">0</span>, <span class=\"ruby-constant\">File</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">SEEK_SET</span> )\n\
116: <span class=\"ruby-identifier\">ofh</span>.<span class=\"ruby-identifier\">print</span>( <span class=\"ruby-identifier\">data</span> )\n\
117: }\n\
118: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Update the current data hash stored in permanent storage with the values
contained in <tt>data</tt>.
</p>
params: ()
category: Instance
type: Public
---
---
- name: SVNRev
desc: |+
SVN Revision
value: "%q$Rev: 437 $"
- name: SVNId
desc: |+
SVN <a href="Id.html">Id</a>
value: "%q$Id: filestore.rb 437 2008-03-28 00:49:20Z deveiant $"
- name: DefaultIoFlags
desc: |+
The default flags to use when opening the backing store file
value: File::RDWR|File::CREAT
Generated with the Darkfish Rdoc Generator.