Class: Rapid::Model::ComponentCreatorWrapper

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/ury_rapid/model/component_creator_wrapper.rb

Overview

An object that wraps a ComponentCreator

A ComponentCreatorWrapper allows a hook proc to be run after every use of a ComponentCreator. Usually, this hook is some sort of registrar function that adds things like update channels and handlers to created components.

This class has a very buzzwordy name, but is mostly harmless.

Instance Method Summary collapse

Constructor Details

#initialize(creator, hook) ⇒ ComponentCreatorWrapper

Initialises a new ComponentCreatorWrapper

Examples:

Construct a useless ComponentCreatorWrapper that does nothing.

ComponentCreatorWrapper.new(creator, ->(x) { x })

Parameters:

  • creator (ComponentCreator)

    The component creator to wrap. Any messages not responded to directly by this ComponentCreatorWrapper are forwarded verbatim to the creator, with the hook invoked on the return value

  • hook (Object)

    An object (usually a Proc) that responds to a #call message containing a component by performing some action and returning back a component. The component may be the original, or some transformation thereof. The hook is invoked silently on any component created.


28
29
30
31
32
33
# File 'lib/ury_rapid/model/component_creator_wrapper.rb', line 28

def initialize(creator, hook)
  fail(ArgumentError, 'Hook not callable') unless hook.respond_to?(:call)

  super(creator)
  @hook = hook
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object

Delegates missing methods to the creator, invoking the hook on return


36
37
38
# File 'lib/ury_rapid/model/component_creator_wrapper.rb', line 36

def method_missing(*args)
  @hook.call(super(*args))
end