Pstore

PStore

ri

 ---------------------------------------------------------- Class: PStore
      PStore implements a file based persistance mechanism based on a
      Hash. User code can store hierarchies of Ruby objects (values) into
      the data store file by name (keys). An object hierarchy may be just
      a single object. User code may later read values back from the data
      store or even update data, as needed.
 
      The transactional behavior ensures that any changes succeed or fail
      together. This can be used to ensure that the data store is not
      left in a transitory state, where some values were upated but
      others were not.
 
      Behind the scenes, Ruby objects are stored to the data store file
      with Marshal. That carries the usual limitations. Proc objects
      cannot be marshalled, for example.
 
 
 Usage example:
 --------------
       require "pstore"
      
       # a mock wiki object...
       class WikiPage
         def initialize( page_name, author, contents )
           @page_name = page_name
           @revisions = Array.new
      
           add_revision(author, contents)
         end
      
         attr_reader :page_name
      
         def add_revision( author, contents )
           @revisions << { :created  => Time.now,
                           :author   => author,
                           :contents => contents }
         end
      
         def wiki_page_references
           [@page_name]   @revisions.last

目次

.scan(/\b(?:[A-Z] [a-z] ){2,}/) end # ... end # create a new page... home_page = WikiPage.new( "HomePage", "James Edward Gray II", "A page about the JoysOfDocumentation..." ) # then we want to update page data and the index together, or not at all... wiki = PStore.new("wiki_pages.pstore") wiki.transaction do # begin transaction
  • 2006/05/15 12:01:02 abort
  • 2006/05/15 12:03:11 at
  • 2006/05/12 19:55:49 CGI::Session
  • 2006/05/15 12:13:18 delete
  • 2006/05/15 12:22:01 fetch
  • 2006/05/15 12:42:14 new
  • 2006/05/15 12:45:34 path
  • 2006/05/12 20:34:31 PStore
  • 2006/05/15 13:06:34 tr
  • 2006/05/15 11:59:35 []
  • 2006/05/15 11:59:42 []=
  • 2006/05/15 11:59:52 ^