Class: Cooper::DataStore

Inherits:
File
  • Object
show all
Defined in:
lib/cooper/datastore.rb

Overview

Interface class for the cooper data store

Constant Summary collapse

LOCATION =
"#{ENV['HOME']}/.cooper_item"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.openObject



6
7
8
# File 'lib/cooper/datastore.rb', line 6

def self.open
  super(LOCATION, 'a+')
end

Instance Method Details

#<<(attributes) ⇒ Object



14
15
16
# File 'lib/cooper/datastore.rb', line 14

def <<(attributes)
  puts attributes.to_json
end

#read(revision) ⇒ Object



18
19
20
21
22
# File 'lib/cooper/datastore.rb', line 18

def read(revision)
  readlines[0..revision]
    .each_with_object({}) { |line, item| item.merge!(JSON.parse(line)) }
    .reject { |_, v| v.nil? }
end

#resetObject



10
11
12
# File 'lib/cooper/datastore.rb', line 10

def reset
  truncate(0)
end