Class: Serega::Attribute::CheckBlock

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

Class Method Summary collapse

Class Method Details

.call(opts, block) ⇒ void

This method returns an undefined value.

Checks :value option or a block 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:

  • opts (Proc)

    Attribute opts, we will check :value option

  • block (Proc)

    Block that returns serialized attribute value

Raises:

  • (Error)

    Error that block has invalid arguments



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

def call(opts, block)
  check_both_provided(opts, block)

  if block
    check_block(block)
  elsif opts.key?(:value)
    check_value(opts[:value])
  end
end