Module: Hollow::Resource::Chains

Defined in:
lib/hollow/resource/chains.rb

Overview

Indicates that a Hollow::Resource class uses chains to perform logic before or after each request.

Instance Method Summary collapse

Instance Method Details

#chain(chain, method, behavior) ⇒ Object

Register a function to invoke before or after a given resource method (or any resource method) is invoked.

Behaviors are invoked in the order in which they are defined within their respective chains, the exception being that behaviors associated with ‘:all` methods are invoked before more specific methods.

Parameters:

  • chain (Symbol)

    Which chain to register the designated behavior with. Must be one of either ‘:before` or `:after`.

  • method (Symbol)

    Which request method triggers the behavior. If ‘:all` is provded, any request method will invoke the behavior.

  • behavior (Proc, Lambda)

    Behavior which accepts one argument (the data accompanying the current request).



24
25
26
27
# File 'lib/hollow/resource/chains.rb', line 24

def chain(chain, method, behavior)
  (self.class_variable_get(:@@chains)[chain][method] ||= []) <<
      behavior
end