require 'csv' module ErrandBoy class CSV class Base def initialize(request) @request = request end def push write_header unless File.exist?(path) File.open path, 'a' do |f| f.puts values end end def include?(key, value) ::CSV.table(path).by_col[key].include?(value) end def path File.join CSV.dir, filename end def filename "#{@request.provider}_#{@request.action}.csv" end def headers raise NotImplementedError, 'Subclass must implement this method!' end def values raise NotImplementedError, 'Subclass must implement this method!' end private def write_header File.write path, headers rescue Errno::ENOENT Dir.mkdir CSV.dir retry end end end end