Class: Garcon::Coercion

Inherits:
Object show all
Defined in:
lib/garcon/chef/coerce/coercer.rb

Overview

This wraps the block that is provided when you register a coercion.

Constant Summary collapse

PASS_THROUGH =

Passes the object on through.

->(obj, _) { obj }

Instance Method Summary collapse

Constructor Details

#initialize(origin, target, &block) ⇒ Coercion

Returns a new instance of Coercion.

Parameters:

  • origin (Class)

    The class that the object is.

  • target (Class)

    The class you wish to coerce to.



97
98
99
100
101
# File 'lib/garcon/chef/coerce/coercer.rb', line 97

def initialize(origin, target, &block)
  @origin  = origin
  @target  = target
  @block   = block_given? ? block : PASS_THROUGH
end

Instance Method Details

#call(object) ⇒ Object

Calls the coercion.

Returns:



107
108
109
# File 'lib/garcon/chef/coerce/coercer.rb', line 107

def call(object)
  @block.call(object, @target)
end