Module: Serega::SeregaPlugins::ExplicitManyOption

Defined in:
lib/serega/plugins/explicit_many_option/explicit_many_option.rb,
lib/serega/plugins/explicit_many_option/validations/check_opt_many.rb

Overview

Plugin :explicit_many_option

Requires the :many option on every relationship attribute (an attribute with the :serializer option or a block defining a nested serializer), so it's always explicit whether it returns one object or many.

Examples:

class BaseSerializer < Serega
  plugin :explicit_many_option
  config.base_serializer = self
end

class PostSerializer < BaseSerializer
  attribute :text

  attribute :user, many: false do
    attribute :name
  end

  attribute :comments, serializer: PostSerializer, many: true
end

Defined Under Namespace

Modules: CheckAttributeParamsInstanceMethods Classes: CheckOptMany

Class Method Summary collapse

Class Method Details

.load_plugin(serializer_class, **_opts) ⇒ void

This method returns an undefined value.

Applies plugin code to specific serializer

Parameters:

  • serializer_class (Class<Serega>)

    Current serializer class

  • _opts (Hash)

    Plugin options



44
45
46
47
48
# File 'lib/serega/plugins/explicit_many_option/explicit_many_option.rb', line 44

def self.load_plugin(serializer_class, **_opts)
  require_relative "validations/check_opt_many"

  serializer_class::CheckAttributeParams.include(CheckAttributeParamsInstanceMethods)
end

.plugin_nameSymbol

Returns Plugin name.

Returns:

  • (Symbol)

    Plugin name



31
32
33
# File 'lib/serega/plugins/explicit_many_option/explicit_many_option.rb', line 31

def self.plugin_name
  :explicit_many_option
end