Sha256: 98f2559154a4b31fdb2222942b32dca28f6b522dc3b8146b3158286386ca172c
Contents?: true
Size: 798 Bytes
Versions: 2
Compression:
Stored size: 798 Bytes
Contents
module CsvRowModel module Export module Base extend ActiveSupport::Concern included do attr_reader :source_model, :context validates :source_model, presence: true end # @param [Model] source_model object to export to CSV # @param [Hash] context def initialize(source_model, context={}) @source_model = source_model @context = OpenStruct.new(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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
csv_row_model-0.4.1 | lib/csv_row_model/export/base.rb |
csv_row_model-0.4.0 | lib/csv_row_model/export/base.rb |