Sha256: d545fe997ff4cf18c7f2f48890d2668e5b38cec068c2e6957153fc63964b02a3

Contents?: true

Size: 749 Bytes

Versions: 1

Compression:

Stored size: 749 Bytes

Contents

require 'csv'
require 'active_support/inflections'

module ActiveModel
  class CsvArraySerializer
    def initialize(objects, options = {})
      @each_serializer = options[:each_serializer]
      @objects = objects
      @options = options
    end

    def to_a
      return ActiveModel::Csverizer.new(nil).to_a if @objects.nil?
      @objects.collect do |object|
        serializer = @each_serializer || ActiveModel::CsverizerFactory
        serializer.new(object, @options).to_a
      end
    end

    def to_csv
      to_a.to_csv
    end

    def attribute_names
      return [] unless @objects
      serializer = @each_serializer || ActiveModel::CsverizerFactory
      serializer.new(@objects.first, @options).attribute_names
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csverizer-0.0.5 lib/active_model/csv_array_serializer.rb