Class: Serega::SeregaUtils::PreloadPaths

Inherits:
Object
  • Object
show all
Defined in:
lib/serega/utils/preload_paths.rb

Overview

Utility that helps to transform preloads to array of paths It is used to validate manually set ‘:preload_path` attribute option has one of allowed values. `:preload_path` option can be used to specify where nested preloads must be attached.

Example:

call({ a: { b: { c: {}, d: {} } }, e: {} })

=> [
     [:a],
     [:a, :b],
     [:a, :b, :c],
     [:a, :b, :d],
     [:e]
   ]

Class Method Summary collapse

Class Method Details

.call(preloads) ⇒ Array

Transforms user provided preloads to array of paths

Parameters:

  • preloads (Array, Hash, String, Symbol, nil, false)

    association(s) to preload

Returns:

  • (Array)

    transformed preloads



30
31
32
33
34
35
# File 'lib/serega/utils/preload_paths.rb', line 30

def call(preloads)
  formatted_preloads = FormatUserPreloads.call(preloads)
  return FROZEN_EMPTY_ARRAY if formatted_preloads.empty?

  paths(formatted_preloads, [], [])
end