Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/druid/Object.rb
Overview
Extend Object class to include save_to_file and load_from_file methods
Class Method Summary collapse
Class Method Details
.load_from_file(filename) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/druid/Object.rb', line 15 def self.load_from_file filename begin file = Zlib::GzipReader.open(filename) rescue Zlib::GzipFile::Error file = File.open(filename, 'r') ensure return nil if ! file #obj = Marshal.load file.read obj = Marshal.load file.read file.close return obj end end |
.save_to_file(obj, filename, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/druid/Object.rb', line 5 def self.save_to_file obj, filename, ={} #obj = self marshal_dump = Marshal.dump(obj) file = File.new(filename,'w') file = Zlib::GzipWriter.new(file) unless [:gzip] == false file.write marshal_dump file.close return obj end |