Class: Serega::SeregaPlugins::Preloads::CheckOptPreloadPath

Inherits:
Object
  • Object
show all
Defined in:
lib/serega/plugins/preloads/validations/check_opt_preload_path.rb

Overview

Validator for attribute :preload_path option

Class Method Summary collapse

Class Method Details

.call(opts) ⇒ void

This method returns an undefined value.

Checks preload_path option

Parameters:

  • opts (Hash)

    Attribute options

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/serega/plugins/preloads/validations/check_opt_preload_path.rb', line 20

def call(opts)
  return unless opts.key?(:preload_path)

  value = opts[:preload_path]
  raise SeregaError, "Invalid option :preload_path => #{value.inspect}. Can be provided only when :preload option provided" unless opts[:preload]
  raise SeregaError, "Invalid option :preload_path => #{value.inspect}. Can be provided only when :serializer option provided" unless opts[:serializer]

  path = Array(value).map!(&:to_sym)
  preloads = FormatUserPreloads.call(opts[:preload])
  allowed_paths = paths(preloads)
  raise SeregaError, "Invalid option :preload_path => #{value.inspect}. Can be one of #{allowed_paths.inspect[1..-2]}" unless allowed_paths.include?(path)
end