Sha256: c59b2fe11c01497cf1ce582ca7c47f99d014364361f4b8e5497e99d502d01e3f

Contents?: true

Size: 827 Bytes

Versions: 9

Compression:

Stored size: 827 Bytes

Contents

# frozen_string_literal: true

module N1Loader
  module ArLazyPreload
    # Context adapter for N1Loader
    class ContextAdapter
      attr_reader :context

      delegate_missing_to :context

      def initialize(context)
        @context = context
      end

      def try_preload_lazily(association_name)
        return unless context&.send(:association_needs_preload?, association_name)

        perform_preloading(association_name)
      end

      def perform_preloading(association_name)
        context_setup = lambda { |records|
          AssociatedContextBuilder.prepare(
            parent_context: self,
            association_name: association_name,
            records: records
          )
        }

        N1Loader::Preloader.new(records, context_setup).preload(association_name)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
n1_loader-1.5.1 lib/n1_loader/ar_lazy_preload/context_adapter.rb
n1_loader-1.5.0 lib/n1_loader/ar_lazy_preload/context_adapter.rb
n1_loader-1.4.4 lib/n1_loader/ar_lazy_preload/context_adapter.rb
n1_loader-1.4.3 lib/n1_loader/ar_lazy_preload/context_adapter.rb
n1_loader-1.4.2 lib/n1_loader/ar_lazy_preload/context_adapter.rb
n1_loader-1.4.1 lib/n1_loader/ar_lazy_preload/context_adapter.rb
n1_loader-1.4.0 lib/n1_loader/ar_lazy_preload/context_adapter.rb
n1_loader-1.3.0 lib/n1_loader/ar_lazy_preload/context_adapter.rb
n1_loader-1.2.0 lib/n1_loader/ar_lazy_preload/context_adapter.rb