mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Cosmetic changes of lib/pstore.rb. Patch by Masaki Matsushita. See #5248.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fcec6b5c0d
commit
a934aeb619
1 changed files with 7 additions and 17 deletions
|
@ -7,10 +7,7 @@
|
||||||
#
|
#
|
||||||
# See PStore for documentation.
|
# See PStore for documentation.
|
||||||
|
|
||||||
|
|
||||||
require "fileutils"
|
|
||||||
require "digest/md5"
|
require "digest/md5"
|
||||||
require "thread"
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# PStore implements a file based persistence mechanism based on a Hash. User
|
# PStore implements a file based persistence mechanism based on a Hash. User
|
||||||
|
@ -141,8 +138,8 @@ class PStore
|
||||||
# Raises PStore::Error if the calling code is not in a PStore#transaction or
|
# Raises PStore::Error if the calling code is not in a PStore#transaction or
|
||||||
# if the code is in a read-only PStore#transaction.
|
# if the code is in a read-only PStore#transaction.
|
||||||
#
|
#
|
||||||
def in_transaction_wr()
|
def in_transaction_wr
|
||||||
in_transaction()
|
in_transaction
|
||||||
raise PStore::Error, "in read-only transaction" if @rdonly
|
raise PStore::Error, "in read-only transaction" if @rdonly
|
||||||
end
|
end
|
||||||
private :in_transaction, :in_transaction_wr
|
private :in_transaction, :in_transaction_wr
|
||||||
|
@ -200,7 +197,7 @@ class PStore
|
||||||
# be read-only. It will raise PStore::Error if called at any other time.
|
# be read-only. It will raise PStore::Error if called at any other time.
|
||||||
#
|
#
|
||||||
def []=(name, value)
|
def []=(name, value)
|
||||||
in_transaction_wr()
|
in_transaction_wr
|
||||||
@table[name] = value
|
@table[name] = value
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
|
@ -210,7 +207,7 @@ class PStore
|
||||||
# be read-only. It will raise PStore::Error if called at any other time.
|
# be read-only. It will raise PStore::Error if called at any other time.
|
||||||
#
|
#
|
||||||
def delete(name)
|
def delete(name)
|
||||||
in_transaction_wr()
|
in_transaction_wr
|
||||||
@table.delete name
|
@table.delete name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -388,9 +385,7 @@ class PStore
|
||||||
if read_only
|
if read_only
|
||||||
begin
|
begin
|
||||||
table = load(file)
|
table = load(file)
|
||||||
if !table.is_a?(Hash)
|
raise Error, "PStore file seems to be corrupted." unless table.is_a?(Hash)
|
||||||
raise Error, "PStore file seems to be corrupted."
|
|
||||||
end
|
|
||||||
rescue EOFError
|
rescue EOFError
|
||||||
# This seems to be a newly-created file.
|
# This seems to be a newly-created file.
|
||||||
table = {}
|
table = {}
|
||||||
|
@ -407,9 +402,7 @@ class PStore
|
||||||
table = load(data)
|
table = load(data)
|
||||||
checksum = Digest::MD5.digest(data)
|
checksum = Digest::MD5.digest(data)
|
||||||
size = data.bytesize
|
size = data.bytesize
|
||||||
if !table.is_a?(Hash)
|
raise Error, "PStore file seems to be corrupted." unless table.is_a?(Hash)
|
||||||
raise Error, "PStore file seems to be corrupted."
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
data.replace(EMPTY_STRING)
|
data.replace(EMPTY_STRING)
|
||||||
[table, checksum, size]
|
[table, checksum, size]
|
||||||
|
@ -417,10 +410,7 @@ class PStore
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_windows?
|
def on_windows?
|
||||||
is_windows = RUBY_PLATFORM =~ /mswin/ ||
|
is_windows = RUBY_PLATFORM =~ /mswin|mingw|bccwin|wince/
|
||||||
RUBY_PLATFORM =~ /mingw/ ||
|
|
||||||
RUBY_PLATFORM =~ /bccwin/ ||
|
|
||||||
RUBY_PLATFORM =~ /wince/
|
|
||||||
self.class.__send__(:define_method, :on_windows?) do
|
self.class.__send__(:define_method, :on_windows?) do
|
||||||
is_windows
|
is_windows
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue