Class: ArLazyPreload::PreloadedRecordsConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/ar_lazy_preload/preloaded_records_converter.rb

Class Method Summary collapse

Class Method Details

.call(preloaded_records) ⇒ Object

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



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ar_lazy_preload/preloaded_records_converter.rb', line 8

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