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. It should not have any *rest or **key arguments

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 }

Parameters:

  • block (Proc)

    Block that returns serialized attribute value

Raises:

  • (SeregaError)

    SeregaError that block has invalid arguments



34
35
36
37
38
# File 'lib/serega/validations/attribute/check_block.rb', line 34

def call(block)
  return unless block

  check_block(block)
end