Class: Anschel::Store
- Inherits:
-
Object
- Object
- Anschel::Store
- Defined in:
- lib/anschel/store.rb
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
-
#initialize(path, log) ⇒ Store
constructor
A new instance of Store.
- #save ⇒ Object
Constructor Details
#initialize(path, log) ⇒ Store
Returns a new instance of Store.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/anschel/store.rb', line 6 def initialize path, log @path = path || '/tmp/anschel.db' @hash = nil if File.exist? @path @hash = JrJackson::Json.load \ File.read(@path), symbolize_keys: true end @hash ||= {} log.info event: 'stats-loaded' end |
Instance Method Details
#[](k) ⇒ Object
17 |
# File 'lib/anschel/store.rb', line 17 def [] k ; @hash[k] end |
#[]=(k, v) ⇒ Object
19 |
# File 'lib/anschel/store.rb', line 19 def []= k,v ; @hash[k] = v ; save end |
#save ⇒ Object
21 22 23 24 25 |
# File 'lib/anschel/store.rb', line 21 def save File.open(@path, 'w') do |f| f.puts JrJackson::Json.dump(@hash) end end |