Class: Zap::Store
- Inherits:
-
Object
- Object
- Zap::Store
- Defined in:
- lib/zap/store.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#store ⇒ Object
Returns the value of attribute store.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #each_pair ⇒ Object
-
#initialize(file) ⇒ Store
constructor
A new instance of Store.
- #to_json ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(file) ⇒ Store
Returns a new instance of Store.
6 7 8 9 10 11 |
# File 'lib/zap/store.rb', line 6 def initialize(file) self.file = file init_file unless File.exists?(file) self.store = Yajl::Parser.parse(File.new(file, 'r')) end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
4 5 6 |
# File 'lib/zap/store.rb', line 4 def file @file end |
#store ⇒ Object
Returns the value of attribute store.
4 5 6 |
# File 'lib/zap/store.rb', line 4 def store @store end |
Instance Method Details
#[](key) ⇒ Object
27 28 29 |
# File 'lib/zap/store.rb', line 27 def [](key) store[key] end |
#[]=(key, value) ⇒ Object
21 22 23 24 25 |
# File 'lib/zap/store.rb', line 21 def []=(key, value) self.store[key] = value self.store.delete(key) if value.nil? value end |
#each_pair ⇒ Object
31 32 33 34 35 |
# File 'lib/zap/store.rb', line 31 def each_pair store.each do |(key, value)| yield key, value end end |
#to_json ⇒ Object
13 14 15 |
# File 'lib/zap/store.rb', line 13 def to_json Yajl::Encoder.encode(store) end |
#write ⇒ Object
17 18 19 |
# File 'lib/zap/store.rb', line 17 def write File.open(file, 'w') { |f| f.write(to_json) } end |