Skip to content

Commit

Permalink
Enhanced RDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
BurdetteLamar committed Jun 29, 2022
1 parent 8de41c1 commit 8f9843e
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions lib/pstore.rb
Expand Up @@ -105,7 +105,7 @@
# end
#
# Instance methods in \PStore may be called only from within a transaction
# ()exception: #path may be called from anywhere).
# (exception: #path may be called from anywhere).
# This assures that the call is executed only when the store is secure and stable.
#
# As seen above, changes in a transaction are made automatically
Expand Down Expand Up @@ -367,9 +367,6 @@ def in_transaction_wr
end
private :in_transaction, :in_transaction_wr

# :call-seq:
# pstore[key]
#
# Returns the object for the given +key+ if the key exists.
# +nil+ otherwise;
# if not +nil+, the returned value is an object or a hierarchy of objects:
Expand All @@ -384,14 +381,11 @@ def in_transaction_wr
# See also {Deep Root Values}[rdoc-ref:PStore@Deep+Root+Values].
#
# Raises an exception if called outside a transaction block.
def [](name)
def [](key)
in_transaction
@table[name]
@table[key]
end

# :call-seq:
# fetch(key)
#
# Like #[], except that it accepts a default value for the store.
# If the root for the given +key+ does not exist:
#
Expand All @@ -404,21 +398,18 @@ def [](name)
# end
#
# Raises an exception if called outside a transaction block.
def fetch(name, default=PStore::Error)
def fetch(key, default=PStore::Error)
in_transaction
unless @table.key? name
unless @table.key? key
if default == PStore::Error
raise PStore::Error, format("undefined root name `%s'", name)
raise PStore::Error, format("undefined root key `%s'", key)
else
return default
end
end
@table[name]
@table[key]
end

# :call-seq:
# pstore[key] = value
#
# Creates or replaces an object or hierarchy of objects
# at the root for +key+:
#
Expand All @@ -430,14 +421,11 @@ def fetch(name, default=PStore::Error)
# See also {Deep Root Values}[rdoc-ref:PStore@Deep+Root+Values].
#
# Raises an exception if called outside a transaction block.
def []=(name, value)
def []=(key, value)
in_transaction_wr
@table[name] = value
@table[key] = value
end

# :call-seq:
# delete(key)
#
# Removes and returns the value at +key+ if it exists:
#
# store = PStore.new('t.store')
Expand All @@ -449,9 +437,9 @@ def []=(name, value)
# Returns +nil+ if there is no such root.
#
# Raises an exception if called outside a transaction block.
def delete(name)
def delete(key)
in_transaction_wr
@table.delete name
@table.delete key
end

# Returns an array of the keys of the existing roots:
Expand All @@ -466,19 +454,16 @@ def roots
@table.keys
end

# :call-seq:
# root?(key)
#
# Returns +true+ if there is a root for +key+, +false+ otherwise:
#
# store.transaction do
# store.root?(:foo) # => true
# end
#
# Raises an exception if called outside a transaction block.
def root?(name)
def root?(key)
in_transaction
@table.key? name
@table.key? key
end

# Returns the string file path used to create the store:
Expand Down

0 comments on commit 8f9843e

Please sign in to comment.