Class: Serega::SeregaPlugins::ExplicitManyOption::CheckOptMany

Inherits:
Object
  • Object
show all
Defined in:
lib/serega/plugins/explicit_many_option/validations/check_opt_many.rb

Overview

Validator for attribute :many option

Class Method Summary collapse

Class Method Details

.call(opts, block = nil) ⇒ void

This method returns an undefined value.

Checks attribute :many option must be provided with relations (attributes with the :serializer option or a block defining a nested serializer)

Parameters:

  • opts (Hash)

    Attribute options

  • block (nil, Proc) (defaults to: nil)

    Attribute block

Raises:



24
25
26
27
28
29
30
31
32
33
# File 'lib/serega/plugins/explicit_many_option/validations/check_opt_many.rb', line 24

def call(opts, block = nil)
  return if !opts[:serializer] && !block

  many_option_exists = opts.key?(:many)
  return if many_option_exists

  raise SeregaError,
    "Attribute option :many [Boolean] must be provided" \
    " for attributes with :serializer option or a block"
end