diff options
author | Luke Kanies <luke@madstop.com> | 2005-06-06 15:13:14 +0000 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2005-06-06 15:13:14 +0000 |
commit | 53240625be7d35dabe29a2e71d5ac99d6f996427 (patch) | |
tree | 594a182c69951b3b8f6fa88f99e0e4cc4aae412e /lib/blink/storage.rb | |
parent | 0dad57a29e84d510a9d530c79b12aa4fba9f334f (diff) | |
download | puppet-53240625be7d35dabe29a2e71d5ac99d6f996427.tar.gz puppet-53240625be7d35dabe29a2e71d5ac99d6f996427.tar.xz puppet-53240625be7d35dabe29a2e71d5ac99d6f996427.zip |
adding new classes and tests
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@294 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/blink/storage.rb')
-rw-r--r-- | lib/blink/storage.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/blink/storage.rb b/lib/blink/storage.rb new file mode 100644 index 000000000..9fc21d38b --- /dev/null +++ b/lib/blink/storage.rb @@ -0,0 +1,48 @@ +# $Id$ + +module Blink + # a class for storing state + class Storage + include Singleton + @@state = Hash.new { |hash,key| + hash[key] = Hash.new(nil) + } + @@splitchar = "\t" + + def initialize + self.class.load + end + + def Storage.load + # XXX I should probably use a better default state dir + Blink[:statefile] ||= "/var/tmp/blinkstate" + return unless File.exists?(Blink[:statefile]) + File.open(Blink[:statefile]) { |file| + file.gets { |line| + myclass, key, value = line.split(@@splitchar) + + @@state[myclass][key] = Marshal::load(value) + } + } + end + + def Storage.state(myclass) + unless myclass.is_a? Class + myclass = myclass.class + end + result = @@state[myclass] + return result + end + + def Storage.store + File.open(Blink[:statefile], File::CREAT|File::WRONLY, 0600) { |file| + @@state.each { |klass, thash| + thash.each { |key,value| + mvalue = Marshal::dump(value) + file.puts([klass,key,mvalue].join(@@splitchar)) + } + } + } + end + end +end |