Sha256: b3ce6b03cb6a76246230f9d727ba97ebb72886bde082cf2afc70f1a97c556c65

Contents?: true

Size: 776 Bytes

Versions: 1

Compression:

Stored size: 776 Bytes

Contents

module CsvRowModel
  module Export
    module Base
      extend ActiveSupport::Concern

      included do
        attr_reader :source_model
        validates :source_model, presence: true
      end

      # @param [Model] source_model object to export to CSV
      # @param [Hash]  context
      def initialize(source_model=nil, context={})
        @source_model = source_model
        super(context: context)
      end

      def to_rows
        [to_row]
      end

      # @return [Array] an array of public_send(column_name) of the CSV model
      def to_row
        formatted_attributes.values
      end

      class_methods do
        def setup(csv, context={}, with_headers: true)
          csv << headers(context) if with_headers
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csv_row_model-1.0.0.beta1 lib/csv_row_model/export/base.rb