Sha256: 4d2ad06c6e5b72cd72fd04d66cca91d6ebcc056f7fcd0162f1601460c18254f6

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module ActiveRecordDataLoader
  module Dsl
    class Model
      attr_reader :klass, :columns, :row_count, :polymorphic_associations, :belongs_to_associations

      def initialize(klass:, configuration:)
        @klass = klass
        @columns = {}
        @row_count = configuration.default_row_count
        @batch_size = configuration.default_batch_size
        @polymorphic_associations = []
        @belongs_to_associations = []
      end

      def count(count)
        @row_count = count
      end

      def batch_size(size = nil)
        @batch_size = (size || @batch_size)
      end

      def column(name, func)
        @columns[name.to_sym] = func
      end

      def polymorphic(assoc_name, &block)
        @polymorphic_associations << PolymorphicAssociation.new(
          @klass, assoc_name
        ).tap { |a| block.call(a) }
      end

      def belongs_to(assoc_name, eligible_set:)
        @belongs_to_associations << BelongsToAssociation.new(@klass, assoc_name, eligible_set)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
active_record_data_loader-1.2.0 lib/active_record_data_loader/dsl/model.rb
active_record_data_loader-1.1.0 lib/active_record_data_loader/dsl/model.rb
active_record_data_loader-1.0.2 lib/active_record_data_loader/dsl/model.rb
active_record_data_loader-1.0.1 lib/active_record_data_loader/dsl/model.rb
active_record_data_loader-1.0.0 lib/active_record_data_loader/dsl/model.rb
active_record_data_loader-0.1.2 lib/active_record_data_loader/dsl/model.rb