Class: Serega::SeregaValidations::Attribute::CheckBlock

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

Overview

Attribute ‘block` parameter validator

Class Method Summary collapse

Class Method Details

.call(block) ⇒ void

This method returns an undefined value.

Checks block parameter provided with attribute. Must have up to two arguments - object and context. Context can be also provided as keyword argument :ctx.

Examples:

without arguments

attribute(:email) { CONSTANT_EMAIL }

with one argument

attribute(:email) { |obj| obj.confirmed_email }

with two arguments

attribute(:email) { |obj, context| context['is_current'] ? obj.email : nil }

with one argument and keyword context

attribute(:email) { |obj, ctx:| obj.email if ctx[:show] }

Parameters:

  • block (Proc)

    Block that returns serialized attribute value

Raises:

  • (SeregaError)

    SeregaError that block has invalid arguments



37
38
39
40
41
# File 'lib/serega/validations/attribute/check_block.rb', line 37

def call(block)
  return unless block

  check_block(block)
end