Class: TinyQ::Permanent

Inherits:
Object
  • Object
show all
Defined in:
lib/tinyq/permanent.rb

Class Method Summary collapse

Class Method Details

.load(filename) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tinyq/permanent.rb', line 16

def self.load filename
    begin
        file = Zlib::GzipReader.open(filename)
    rescue Zlib::GzipFile::Error
        file = File.open(filename, 'r')
    ensure
        obj = Marshal.load file.read
        file.close
        return obj
    end
end

.remove(filename) ⇒ Object



28
29
30
# File 'lib/tinyq/permanent.rb', line 28

def self.remove filename
    File.delete(file)
end

.store(obj, filename, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/tinyq/permanent.rb', line 7

def self.store obj, filename, options = {}
    dump = Marshal.dump(obj)
    file = File.new(filename, 'w')
    file = Zlib::GzipWriter.new(file) unless options[:gzip] == false
    file.write dump
    file.close
    return obj
end