Class: Eigindir::Coercer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/eigindir/coercer.rb

Overview

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

Class Coercer creates the proc to be called by attribute getter and setter

Author:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(coerce: nil, strict: nil) ⇒ Coercer

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.

Returns a new instance of Coercer.



23
24
25
26
27
28
# File 'lib/eigindir/coercer.rb', line 23

def initialize(coerce: nil, strict: nil)
  @coerce = coerce
  @strict = strict
  check_type
  check_arity
end

Class Method Details

.new(coerce: nil, strict: nil) ⇒ Eigindir::Coercer

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.

Checks the coercer validity and creates its istance

Parameters:

  • [Proc, (Hash)

    a customizable set of options

  • [Boolean] (Hash)

    a customizable set of options

Returns:



18
19
20
# File 'lib/eigindir/coercer.rb', line 18

def self.new(coerce: nil, strict: nil)
  super if coerce
end

Instance Method Details

#call(instance, value) ⇒ 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 a value in a context of some instance

Parameters:

  • instance (Object)

    The object whose method is used to coerce value

  • value (Object)

    The value to coerce

Returns:

  • (Object)

    the coerced value



38
39
40
# File 'lib/eigindir/coercer.rb', line 38

def call(instance, value)
  proc.call(instance, value) if value || strict
end