class Guacamole::Callbacks::CallbackProxy

A proxy class around the callback class itself.

The sole reason for its existence is to specify multiple callback runs at once. The alternative would have been to nest the ‘run_callbacks` calls within the caller. It was decided to have bit more complex proxy class to hide those details from the caller.

@example

callbacks = Callbacks.callbacks_for(model)
callbacks.run_callbacks :save, :create do
  CakeCollection.create model
end

@private

Attributes

callbacks[R]

Public Class Methods

new(callbacks) click to toggle source

Create a new proxy with the original callbacks class as input

@param [Callbacks] callbacks The original callback class to be executed

# File lib/guacamole/callbacks.rb, line 183
def initialize(callbacks)
  @callbacks = callbacks
end

Public Instance Methods

run_callbacks(*callbacks_to_run, &block) click to toggle source

Runs the given kinds of callbacks

@param [Array<Symbol>] callbacks_to_run One or more kinds of callbacks to be run @yield Will call the code block wrapped by the given callbacks

# File lib/guacamole/callbacks.rb, line 191
def run_callbacks(*callbacks_to_run, &block)
  outer = callbacks_to_run.pop

  if callbacks_to_run.empty?
    @callbacks.run_callbacks(outer, &block)
  else
    @callbacks = run_callbacks(*callbacks_to_run) do
      @callbacks.run_callbacks(outer, &block)
    end
  end
end