Class: Zemanta::Cache::Disk
- Inherits:
-
Object
- Object
- Zemanta::Cache::Disk
- Defined in:
- lib/zemanta/cache/disk.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
Returns the value of attribute db.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(directory = 'tmp/db') ⇒ Disk
constructor
A new instance of Disk.
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
#db ⇒ Object
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 |