diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/yaml/store.rb | 21 |
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 |