Sha256: e33a07817df9550bff0ac7833c4863a5621cfb99062f1aef042156d186469696

Contents?: true

Size: 535 Bytes

Versions: 9

Compression:

Stored size: 535 Bytes

Contents

# frozen_string_literal: true

module ActiveRecordCustomPreloader
  class Preloader
    attr_reader :klass, :name, :args

    def initialize(klass, name, args)
      @klass = klass
      @name = name
      @args = args
    end

    # override this method in a subclass to provide customized preloading behavior
    def preload(records)
      values = args.fetch(:values).call(records)
      records.each do |record|
        value = values[record.id]
        record._set_custom_preloaded_value(name, value)
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
active_record_custom_preloader-2.0.0 lib/active_record_custom_preloader/preloader.rb
active_record_custom_preloader-1.0.0 lib/active_record_custom_preloader/preloader.rb
active_record_custom_preloader-0.5.1 lib/active_record_custom_preloader/preloader.rb
active_record_custom_preloader-0.5.0 lib/active_record_custom_preloader/preloader.rb
active_record_custom_preloader-0.4.2 lib/active_record_custom_preloader/preloader.rb
active_record_custom_preloader-0.4.1 lib/active_record_custom_preloader/preloader.rb
active_record_custom_preloader-0.4.0 lib/active_record_custom_preloader/preloader.rb
active_record_custom_preloader-0.3.0 lib/active_record_custom_preloader/preloader.rb
active_record_custom_preloader-0.2.2 lib/active_record_custom_preloader/preloader.rb