Class: Zemanta::Cache::Disk

Inherits:
Object
  • Object
show all
Defined in:
lib/zemanta/cache/disk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory = 'tmp/db') ⇒ Disk

Returns a new instance of Disk.



6
7
8
9
# File 'lib/zemanta/cache/disk.rb', line 6

def initialize(directory='tmp/db')
  @db = Pathname.new(directory)
  @db.mkpath
end

Instance Attribute Details

#dbObject

Returns the value of attribute db.



4
5
6
# File 'lib/zemanta/cache/disk.rb', line 4

def db
  @db
end

Instance Method Details

#[](key) ⇒ Object



11
12
13
14
# File 'lib/zemanta/cache/disk.rb', line 11

def [](key)
  file = @db.join(key)
  file.read if file.exist?
end

#[]=(key, value) ⇒ Object



16
17
18
# File 'lib/zemanta/cache/disk.rb', line 16

def []=(key,value)
  @db.join(key).open('w') {|f| f.write(value.to_s)}
end