Class: Hanami::Utils::Callbacks::Factory Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/utils/callbacks.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.

Callback factory

Since:

  • 0.1.0

Class Method Summary collapse

Class Method Details

.fabricate(callback) ⇒ Callback, MethodCallback

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.

Instantiates a `Callback` according to if it responds to #call.

Examples:

require 'hanami/utils/callbacks'

callable = Proc.new{} # it responds to #call
method   = :upcase    # it doesn't responds to #call

Hanami::Utils::Callbacks::Factory.fabricate(callable).class
  # => Hanami::Utils::Callbacks::Callback

Hanami::Utils::Callbacks::Factory.fabricate(method).class
  # => Hanami::Utils::Callbacks::MethodCallback

Parameters:

  • callback (Object)

    the object that needs to be wrapped

Returns:

Since:

  • 0.1.0


206
207
208
209
210
211
212
# File 'lib/hanami/utils/callbacks.rb', line 206

def self.fabricate(callback)
  if callback.respond_to?(:call)
    Callback.new(callback)
  else
    MethodCallback.new(callback)
  end
end