Sha256: 163fd8e1d0fbbcc220405a88be3f1177808c4372b50d179fbe2d7abbf76d4e63

Contents?: true

Size: 608 Bytes

Versions: 2

Compression:

Stored size: 608 Bytes

Contents

module ActiveModel
  class ArrayExporter
    attr_reader :collection, :exporter, :scope

    def initialize(collection, options = {})
      @collection = collection
      @scope      = options[:scope]
      @exporter   = options[:exporter]
    end

    def to_csv
      CSV.generate do |file|
        collection.each do |object|
          exporter = exporter_for(object)
          file << exporter.values
        end
      end
    end

    private

    def exporter_for(object)
      exporter_class = exporter || Exporter.exporter_for(object)
      exporter_class.new(object, scope: scope)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_model_exporters-0.0.3 lib/active_model/array_exporter.rb
active_model_exporters-0.0.2 lib/active_model/array_exporter.rb