Class: Serega::SeregaValidations::Attribute::CheckOptBaseSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/serega/validations/attribute/check_opt_base_serializer.rb

Overview

Attribute :base_serializer option validator

Class Method Summary collapse

Class Method Details

.call(opts, block = nil) ⇒ void

This method returns an undefined value.

Checks attribute :base_serializer option. It specifies the parent class for the nested serializer defined with the attribute block, so it makes sense only when a block is provided.

Parameters:

  • opts (Hash)

    Attribute options

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

    Attribute block (defines a nested serializer)

Raises:

  • (SeregaError)

    SeregaError that option has invalid value



26
27
28
29
30
31
32
33
34
35
# File 'lib/serega/validations/attribute/check_opt_base_serializer.rb', line 26

def call(opts, block = nil)
  return unless opts.key?(:base_serializer)

  raise SeregaError, "Option :base_serializer can be used only with a block" unless block

  value = opts[:base_serializer]
  return if value.is_a?(Class) && (value <= Serega)

  raise SeregaError, "Invalid option :base_serializer => #{value.inspect}. Must be a Serega subclass"
end