Class: Headcount::Persistence::File

Inherits:
Object
  • Object
show all
Defined in:
lib/headcount/persistence/file.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, format) ⇒ File

Returns a new instance of File.



4
5
6
7
# File 'lib/headcount/persistence/file.rb', line 4

def initialize(path, format)
  @path = path
  @format = format
end

Instance Method Details

#save(headcounts, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/headcount/persistence/file.rb', line 9

def save(headcounts, options = {})
  ::File.delete(@path) if ::File.exists?(@path) if options[:reset]
    
  ::File.open(@path, 'a') do |file|
    headcounts.each do |headcount|
      file.puts headcount.to_json
    end
  end
end