Sha256: 392349bbd8abc293694b30dcff7d4830ad8d8efb522cff222c793a1230c20f40

Contents?: true

Size: 709 Bytes

Versions: 1

Compression:

Stored size: 709 Bytes

Contents

# frozen_string_literal: true

module Acb
  module Base
    extend ActiveSupport::Concern

    class_methods do
      def columns
        @columns ||= Columns.new
      end

      def add_column(name:, **options)
        columns.push(name, **options)
      end
    end

    def to_csv(**options)
      CSV.generate(**options) do |csv|
        csv << self.class.columns.header
        data.each do |row|
          csv << get_data_from(row)
        end
      end
    end
    alias content_string to_csv

    private

    def data
      @data = @data.preload(relations) if respond_to?(:relations)
      @data.find_each
    end

    def get_data_from(row)
      self.class.columns.get_data(row)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acb-0.1.5 lib/acb/base.rb