Class: Serega::SeregaPlugins::Metadata::MetaAttribute::CheckBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/serega/plugins/metadata/validations/check_block.rb

Overview

Validator for meta_attribute block parameter

Class Method Summary collapse

Class Method Details

.call(block) ⇒ void

This method returns an undefined value.

Checks block provided with attribute Block must have up to two arguments - object(s) and context.

Examples:

without arguments

(:version) { CONSTANT_VERSION }

with one argument

metadata(:paging) { |scope| { { page: scope.page, per_page: scope.per_page, total_count: scope.total_count } }

with two arguments

metadata(:paging) { |scope, context| { { ... } if context[:pagy] }

Parameters:

  • block (Proc)

    Block that returns serialized meta attribute value

Raises:

  • (SeregaError)

    SeregaError that block has invalid arguments



31
32
33
34
# File 'lib/serega/plugins/metadata/validations/check_block.rb', line 31

def call(block)
  signature = SeregaUtils::MethodSignature.call(block, pos_limit: 2, keyword_args: [])
  raise SeregaError, block_error unless %w[0 1 2].include?(signature)
end