Skip to content

Commit c59d4a0

Browse files
committed
Enhanced RDoc
1 parent 81a266d commit c59d4a0

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

lib/pstore.rb

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,27 @@
1010

1111
require "digest"
1212

13-
# An instance of class \PStore can store and retrieve Ruby objects --
14-
# not just strings or raw data, but objects of many kinds.
13+
# \PStore implements a file based persistence mechanism based on a Hash.
14+
# User code can store hierarchies of Ruby objects (values)
15+
# into the data store by name (keys).
16+
# An object hierarchy may be just a single object.
17+
# User code may later read values back from the data store
18+
# or even update data, as needed.
19+
#
20+
# The transactional behavior ensures that any changes succeed or fail together.
21+
# This can be used to ensure that the data store is not left in a transitory state,
22+
# where some values were updated but others were not.
23+
#
24+
# Behind the scenes, Ruby objects are stored to the data store file with Marshal.
25+
# That carries the usual limitations. Proc objects cannot be marshalled,
26+
# for example.
27+
#
1528
# There are three key terms here (details at the links):
1629
#
1730
# - {Store}[rdoc-ref:PStore@The+Store]: a store is an instance of \PStore.
1831
# - {Roots}[rdoc-ref:PStore@Roots]: the store is hash-like;
1932
# each root is a key for a stored object.
20-
# - {Transactions}[rdoc-ref:PStore@Transactions]: each transaction is a ollection
33+
# - {Transactions}[rdoc-ref:PStore@Transactions]: each transaction is a collection
2134
# of prospective changes to the store;
2235
# a transaction is defined in the block given with a call
2336
# to PStore#transaction.
@@ -37,7 +50,7 @@
3750
# end
3851
#
3952
# To avoid modifying the example store, some examples first execute
40-
# <tt>temp = store.dup</tt>, then apply changes to +temp+
53+
# <tt>temp = store.dup</tt>, then apply changes to +temp+.
4154
#
4255
# == The Store
4356
#
@@ -59,22 +72,26 @@
5972
# Each root has a key and a value, just as in a hash:
6073
#
6174
# - Key: as in a hash, the key can be (almost) any object;
62-
# see {Hash}[https://docs.ruby-lang.org/en/master/Hash.html].
75+
# see {Hash Keys}[https://docs.ruby-lang.org/en/master/Hash.html#class-Hash-label-Hash+Keys].
6376
# You may find it convenient to keep it simple by using only
6477
# symbols or strings as keys.
65-
# - Value: the value truly may be any object, and in fact can be a collection
78+
# - Value: the value may be any object that can be serialized by \Marshal
79+
# (see {Marshal::dump}[https://docs.ruby-lang.org/en/master/Marshal.html#method-c-dump])
80+
# and in fact may be a collection
6681
# (e.g., an array, a hash, a set, a range, etc).
67-
# That collection may in turn contain nested collections, to any depth.
82+
# That collection may in turn contain nested objects,
83+
# including collections, to any depth;
84+
# those objects must also be Marshal-serializable.
6885
# See {Deep Root Values}[rdoc-ref:PStore@Deep+Root+Values].
6986
#
7087
# == Transactions
7188
#
7289
# A call to PStore#transaction must have a block.
7390
#
74-
# A transaction consists of just those \PStore method calls in the block
75-
# that would modify the store; those methods are #[]= and #delete.
76-
# Note that the block may contain any code whatsoever
91+
# The block may contain any code whatsoever
7792
# except a nested call to #transaction.
93+
# The transaction itself consists of the \PStore method calls in the block
94+
# that would modify the store: calls to #[]= and #delete.
7895
#
7996
# An instance method in \PStore may be called only from within a transaction
8097
# (with the exception the #path may be called from anywhere).
@@ -416,7 +433,7 @@ def []=(name, value)
416433
# :call-seq:
417434
# delete(key)
418435
#
419-
# Removes and returns the root for +key+ if it exists:
436+
# Removes and returns the value at +key+ if it exists:
420437
#
421438
# store = PStore.new('t.store')
422439
# store.transaction do
@@ -467,8 +484,8 @@ def path
467484
@filename
468485
end
469486

470-
# Exits the current transaction block after committing any changes
471-
# specified in that block.
487+
# Exits the current transaction block, committing any changes
488+
# specified in the transaction block.
472489
# See {Committing or Aborting}[rdoc-ref:PStore@Committing+or+Aborting].
473490
#
474491
# Raises an exception if called outside a transaction block.
@@ -478,8 +495,8 @@ def commit
478495
throw :pstore_abort_transaction
479496
end
480497

481-
# Exits the current transaction block, ignoring any changes
482-
# specified in that block.
498+
# Exits the current transaction block, discarding any changes
499+
# specified in the transaction block.
483500
# See {Committing or Aborting}[rdoc-ref:PStore@Committing+or+Aborting].
484501
#
485502
# Raises an exception if called outside a transaction block.
@@ -489,11 +506,11 @@ def abort
489506
throw :pstore_abort_transaction
490507
end
491508

492-
# Defines a transaction block for the store.
509+
# Opens a transaction block for the store.
493510
# See {Transactions}[rdoc-ref:PStore@Transactions].
494511
#
495-
# With argument +read_only+ as +false+, the block may contain any Ruby code,
496-
# including calls to \PStore methods other #transaction.
512+
# With argument +read_only+ as +false+, the block may both read from
513+
# and write to the store.
497514
#
498515
# With argument +read_only+ as +true+, the block may not include calls
499516
# to #transaction, #[]=, or #delete.

0 commit comments

Comments
 (0)