Class: RailsContractSync::Runtime::ObservationStore

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_contract_sync/runtime/observation_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ObservationStore

Returns a new instance of ObservationStore.



7
8
9
# File 'lib/rails_contract_sync/runtime/observation_store.rb', line 7

def initialize(path)
  @path = path
end

Instance Method Details

#allObject



16
17
18
19
20
# File 'lib/rails_contract_sync/runtime/observation_store.rb', line 16

def all
  return [] unless File.exist?(@path)

  File.readlines(@path, chomp: true).reject(&:empty?).map { |line| JSON.parse(line) }
end

#append(hash) ⇒ Object



11
12
13
14
# File 'lib/rails_contract_sync/runtime/observation_store.rb', line 11

def append(hash)
  FileUtils.mkdir_p(File.dirname(@path))
  File.open(@path, "a") { |f| f.puts(JSON.generate(hash)) }
end

#clearObject



22
23
24
# File 'lib/rails_contract_sync/runtime/observation_store.rb', line 22

def clear
  File.delete(@path) if File.exist?(@path)
end