Sha256: f6c9e2d79b76a8b8c52ebeaaee68aa1b69ce1a5f217b0570544064994753f77a

Contents?: true

Size: 634 Bytes

Versions: 9

Compression:

Stored size: 634 Bytes

Contents

# frozen_string_literal: true

module ArLazyPreload
  class PreloadedRecordsConverter
    # For different versions of rails we have different records class
    # for ~> 6.1.0 it returns plain array
    # for ~> 6.0.0 it returns ActiveRecord::Relation
    def self.call(preloaded_records)
      case preloaded_records
      when Array
        preloaded_records
      when ::ActiveRecord::Relation
        raise(ArgumentError, "The relation is not preloaded") unless preloaded_records.loaded?

        preloaded_records.to_a
      else
        raise(ArgumentError, "Unsupported class for preloaded records")
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ar_lazy_preload-2.1.0 lib/ar_lazy_preload/preloaded_records_converter.rb
ar_lazy_preload-2.0.0 lib/ar_lazy_preload/preloaded_records_converter.rb
ar_lazy_preload-1.1.2 lib/ar_lazy_preload/preloaded_records_converter.rb
ar_lazy_preload-1.1.1 lib/ar_lazy_preload/preloaded_records_converter.rb
ar_lazy_preload-1.1.0 lib/ar_lazy_preload/preloaded_records_converter.rb
ar_lazy_preload-1.0.0 lib/ar_lazy_preload/preloaded_records_converter.rb
ar_lazy_preload-0.7.0 lib/ar_lazy_preload/preloaded_records_converter.rb
ar_lazy_preload-0.6.2 lib/ar_lazy_preload/preloaded_records_converter.rb
ar_lazy_preload-0.6.1 lib/ar_lazy_preload/preloaded_records_converter.rb