Sha256: f85ec6e6a62c22c896686d4153d9fd3b962688e07e0f7552b67d412738f0f8d6

Contents?: true

Size: 964 Bytes

Versions: 2

Compression:

Stored size: 964 Bytes

Contents

# frozen_string_literal: true

require "csvbuilder/dynamic/columns/core/concerns/dynamic_columns_base"
require "csvbuilder/exporter/concerns/export/attributes"
require "csvbuilder/dynamic/columns/exporter/internal/export/dynamic_column_attribute"

module Csvbuilder
  module Export
    module DynamicColumns
      extend ActiveSupport::Concern
      include DynamicColumnsBase

      included do
        ensure_define_dynamic_attribute_method
      end

      def dynamic_column_attribute_objects
        @dynamic_column_attribute_objects ||= array_to_block_hash(self.class.dynamic_column_names) do |column_name|
          self.class.dynamic_attribute_class.new(column_name, self)
        end
      end

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

      class_methods do
        def dynamic_attribute_class
          DynamicColumnAttribute
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
csvbuilder-dynamic-columns-exporter-0.1.1 lib/csvbuilder/dynamic/columns/exporter/concerns/export/dynamic_columns.rb
csvbuilder-dynamic-columns-exporter-0.1.0 lib/csvbuilder/dynamic/columns/exporter/concerns/export/dynamic_columns.rb