Module: DataMapper::Serializer::ValidationErrors::ToCsv

Included in:
Validations::ValidationErrors
Defined in:
lib/dm-serializer/to_csv.rb

Instance Method Summary collapse

Instance Method Details

#to_csv(*args) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dm-serializer/to_csv.rb', line 34

def to_csv(*args)
  options = args.first || {}
  options = options.to_h if options.respond_to?(:to_h)
  options[:writer] = '' unless options.has_key? :writer

  CSV.generate(options[:writer]) do |csv|
    errors.each do |key, value|
      value.each do |error|
        row = []
        row << key.to_s
        row << error.to_s
        csv << row
      end
    end
  end
end