Class: Filebase::Drivers::Marshal
- Inherits:
-
Object
- Object
- Filebase::Drivers::Marshal
show all
- Includes:
- Mixin
- Defined in:
- lib/filebase/drivers/marshal.rb
Instance Method Summary
collapse
Methods included from Mixin
#count, #delete, #has_key?, #keys, #path, #root
Constructor Details
#initialize(root) ⇒ Marshal
Returns a new instance of Marshal.
10
11
12
13
|
# File 'lib/filebase/drivers/marshal.rb', line 10
def initialize( root )
super
@extension = "marshal"
end
|
Instance Method Details
#all ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/filebase/drivers/marshal.rb', line 15
def all
Dir["#{@root}/*.marshal"].map do |file|
obj = File.open(file) { |f| ::Marshal.load(f) }
obj['key'] = File.basename(file, '.marshal') if obj.is_a? Hash
obj or nil
end
end
|
#find(key) ⇒ Object
23
24
25
26
27
|
# File 'lib/filebase/drivers/marshal.rb', line 23
def find( key )
obj = File.open( path(key) ) { |f| ::Marshal.load(f) } rescue nil
obj['key'] = key if obj.is_a? Hash
obj or nil end
|
#find_keys(keys) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/filebase/drivers/marshal.rb', line 29
def find_keys(keys)
keys.map do |key|
obj = File.open( path(key) ) { |f| ::Marshal.load(f) } rescue nil
obj['key'] = key if obj.is_a? Hash
obj or nil end
end
|
#write(key, object) ⇒ Object
37
38
39
|
# File 'lib/filebase/drivers/marshal.rb', line 37
def write( key, object )
File.open( path(key), "w" ) { |f| ::Marshal.dump(object, f); true }
end
|