summaryrefslogtreecommitdiff
path: root/lib/yaml/store.rb
diff options
context:
space:
mode:
authorkazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-29 13:43:46 +0000
committerkazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-29 13:43:46 +0000
commit158cf62b53820bd5a0ff790173bb9d65f54daa13 (patch)
tree7edacf4941162965623feff3c7143d7dd7c40841 /lib/yaml/store.rb
parent2eb0ad76e12204b78821456fb7b9cb19ed69a078 (diff)
fix YAML::Store
* lib/yaml/store.rb (YAML::Store#initialize): Fix arguments. [ruby-dev:49821] [Bug #12800] * test/yaml/test_store.rb: Add tests from test/test_pstore.rb. * test/yaml/test_store.rb (YAMLStoreTest#test_with_options): Add options test. * lib/yaml/store.rb (YAML::Store#dump): Revert to to_yaml. * lib/yaml/store.rb (YAML::Store#empty_marshal_data): Use to_yaml with options. * lib/yaml/store.rb (YAML::Store#empty_marshal_checksum): Use CHECKSUM_ALGO. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56291 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/yaml/store.rb')
-rw-r--r--lib/yaml/store.rb21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/yaml/store.rb b/lib/yaml/store.rb
index 57ef0ba500..8a4c22fb4d 100644
--- a/lib/yaml/store.rb
+++ b/lib/yaml/store.rb
@@ -39,23 +39,28 @@ require 'pstore'
class YAML::Store < PStore
# :call-seq:
- # initialize( file_name, yaml_opts = {} )
+ # initialize( file_name, thread_safe = false, yaml_opts = {} )
#
# Creates a new YAML::Store object, which will store data in +file_name+.
# If the file does not already exist, it will be created.
#
+ # YAML::Store objects are always reentrant. But if _thread_safe_ is set to true,
+ # then it will become thread-safe at the cost of a minor performance hit.
#
# Options passed in through +yaml_opts+ will be used when converting the
# store to YAML via Hash#to_yaml().
- def initialize file_name, yaml_opts = {}
- @opt = yaml_opts
- super
+ def initialize( *o )
+ @opt = {}
+ if o.last.is_a? Hash
+ @opt.update(o.pop)
+ end
+ super(*o)
end
# :stopdoc:
def dump(table)
- YAML.dump @table
+ @table.to_yaml(@opt)
end
def load(content)
@@ -71,12 +76,10 @@ class YAML::Store < PStore
false
end
- EMPTY_MARSHAL_DATA = YAML.dump({})
- EMPTY_MARSHAL_CHECKSUM = Digest::MD5.digest(EMPTY_MARSHAL_DATA)
def empty_marshal_data
- EMPTY_MARSHAL_DATA
+ {}.to_yaml(@opt)
end
def empty_marshal_checksum
- EMPTY_MARSHAL_CHECKSUM
+ CHECKSUM_ALGO.digest(empty_marshal_data)
end
end