Module: Lotus::Validations::Coercions Private

Defined in:
lib/lotus/validations/coercions.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Coercions for attribute’s values.

Since:

  • 0.1.0

Class Method Summary collapse

Class Method Details

.coerce(coercer, value, &blk) ⇒ Object?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Coerces the given values with the given type

 @param coercer [Class] the type

Parameters:

  • value (Array)

    of objects to be coerced

  • blk (Proc)

    an optional block to pass to the custom coercer

Returns:

  • (Object, nil)

    The result of the coercion, if possible

Raises:

  • (ArgumentError)

    if the custom coercer’s ‘#initialize` has a wrong arity.

Since:

  • 0.1.0



22
23
24
25
26
27
28
# File 'lib/lotus/validations/coercions.rb', line 22

def self.coerce(coercer, value, &blk)
  if ::Lotus::Utils::Kernel.respond_to?(coercer.to_s)
    ::Lotus::Utils::Kernel.__send__(coercer.to_s, value, &blk) rescue nil
  else
    coercer.new(value, &blk)
  end
end