aboutsummaryrefslogtreecommitdiffstats
path: root/lib/yaml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/yaml')
-rw-r--r--lib/yaml/store.rb85
1 files changed, 19 insertions, 66 deletions
diff --git a/lib/yaml/store.rb b/lib/yaml/store.rb
index d36887720f..2ffa9554b9 100644
--- a/lib/yaml/store.rb
+++ b/lib/yaml/store.rb
@@ -3,74 +3,27 @@
#
require 'yaml'
require 'pstore'
-require 'fileutils'
-module YAML
+class YAML::Store < PStore
+ def initialize( *o )
+ @opt = YAML::DEFAULTS.dup
+ if String === o.first
+ super(o.shift)
+ end
+ if o.last.is_a? Hash
+ @opt.update(o.pop)
+ end
+ end
- class Store < PStore
- #
- # Constructor
- #
- def initialize( *o )
- @opt = YAML::DEFAULTS.dup
- if String === o.first
- super(o.shift)
- end
- if o.last.is_a? Hash
- @opt.update(o.pop)
- end
- end
+ def dump(table)
+ @table.to_yaml(@opt)
+ end
- #
- # Override Pstore#transaction
- #
- def transaction
- raise YAML::Error, "nested transaction" if @transaction
- raise YAML::Error, "no filename for transaction" unless @filename
- begin
- @transaction = true
- value = nil
- backup = @filename+"~"
- if File::exist?(@filename)
- file = File::open(@filename, "rb+")
- orig = true
- else
- @table = {}
- file = File::open(@filename, "wb+")
- file.write( @table.to_yaml( @opt ) )
- end
- file.flock(File::LOCK_EX)
- if orig
- FileUtils::copy @filename, backup
- @table = YAML::load( file )
- end
- begin
- catch(:pstore_abort_transaction) do
- value = yield(self)
- end
- rescue Exception
- @abort = true
- raise
- ensure
- unless @abort
- begin
- file.rewind
- file.write( @table.to_yaml( @opt ) )
- file.truncate(file.pos)
- rescue
- File::rename backup, @filename if File::exist?(backup)
- raise
- end
- end
- @abort = false
- end
- ensure
- @table = nil
- @transaction = false
- file.close if file
- end
- value
- end
- end
+ def load(content)
+ YAML::load(content)
+ end
+ def load_file(file)
+ YAML::load(file)
+ end
end