Class: Rockit::HashStore
- Inherits:
-
Object
- Object
- Rockit::HashStore
- Defined in:
- lib/rockit/hash_store.rb
Constant Summary
- DIR =
'.rockit'- FILE =
'hash'
Instance Attribute Summary (collapse)
-
- (Object) dir
Returns the value of attribute dir.
-
- (Object) filename
Returns the value of attribute filename.
Instance Method Summary (collapse)
- - (Object) [](key)
- - (Object) []=(key, value)
- - (Object) clear
-
- (HashStore) initialize(dir = DIR, filename = FILE)
constructor
A new instance of HashStore.
Constructor Details
- (HashStore) initialize(dir = DIR, filename = FILE)
A new instance of HashStore
10 11 12 13 |
# File 'lib/rockit/hash_store.rb', line 10 def initialize(dir=DIR, filename=FILE) @dir = dir @filename = filename end |
Instance Attribute Details
- (Object) dir
Returns the value of attribute dir
8 9 10 |
# File 'lib/rockit/hash_store.rb', line 8 def dir @dir end |
- (Object) filename
Returns the value of attribute filename
8 9 10 |
# File 'lib/rockit/hash_store.rb', line 8 def filename @filename end |
Instance Method Details
- (Object) [](key)
21 22 23 24 25 |
# File 'lib/rockit/hash_store.rb', line 21 def [](key) if m = File.read(filepath).match(/^#{key}:(.*)$/) m[1] end end |
- (Object) []=(key, value)
27 28 29 30 31 |
# File 'lib/rockit/hash_store.rb', line 27 def []=(key, value) contents = File.read(filepath) contents << "#{key}:#{value}\n" unless contents.gsub!(/^#{key}:.*$/, "#{key}:#{value}") File.open(filepath, 'w') {|f| f.write(contents) } end |
- (Object) clear
15 16 17 18 19 |
# File 'lib/rockit/hash_store.rb', line 15 def clear p = File.join(@dir,@filename) File.delete(p) if File.exists?(p) Dir.rmdir(@dir) if File.exists?(@dir) end |