class Procrastinator::TaskStore::SimpleCommaStore::CSVFileTransaction
Adds CSV parsing to the file reading
Public Instance Methods
transact(writable: nil) { |parse(file_str)| ... }
click to toggle source
(see FileTransaction#transact
)
Calls superclass method
Procrastinator::FileTransaction#transact
# File lib/procrastinator/task_store/simple_comma_store.rb, line 144 def transact(writable: nil) super(writable: writable) do |file_str| yield(parse(file_str)) end end
Private Instance Methods
correct_types(data)
click to toggle source
# File lib/procrastinator/task_store/simple_comma_store.rb, line 166 def correct_types(data) non_empty_keys = [:run_at, :expire_at, :attempts, :last_fail_at] data.collect do |hash| non_empty_keys.each do |key| hash.delete(key) if hash[key].is_a?(String) && hash[key].empty? end hash[:attempts] ||= 0 # hash[:data] = (hash[:data] || '').gsub('""', '"') hash[:queue] = hash[:queue].to_sym hash end end
parse(csv_string)
click to toggle source
# File lib/procrastinator/task_store/simple_comma_store.rb, line 152 def parse(csv_string) data = CSV.parse(csv_string, headers: true, header_converters: :symbol, skip_blanks: true, converters: READ_CONVERTER, force_quotes: true).to_a headers = data.shift || HEADERS data = data.collect do |d| headers.zip(d).to_h end correct_types(data) end