Class: Exekutor::Internal::Hooks

Inherits:
Object
  • Object
show all
Includes:
Callbacks
Defined in:
lib/exekutor/internal/hooks.rb

Overview

The internal implementation of the Exekutor hooks

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Callbacks

#add_callback

Class Method Details

.on(type, *args) ⇒ Object

Executes an :on callback with the given type.



39
40
41
# File 'lib/exekutor/internal/hooks.rb', line 39

def self.on(type, *args)
  ::Exekutor.hooks.send(:run_callbacks, :on, type, *args)
end

.run(type, *args, &block) ⇒ Object

Executes the :before, :around, and :after callbacks with the given type.



44
45
46
# File 'lib/exekutor/internal/hooks.rb', line 44

def self.run(type, *args, &block)
  ::Exekutor.hooks.send(:with_callbacks, type, *args, &block)
end

Instance Method Details

#<<(callback) ⇒ Object

See Also:



34
35
36
# File 'lib/exekutor/internal/hooks.rb', line 34

def <<(callback)
  register callback
end

#register(callback = nil, &block) ⇒ Object

Registers a hook to be called.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/exekutor/internal/hooks.rb', line 18

def register(callback = nil, &block)
  if callback
    callback = callback.new if callback.is_a? Class
    raise "callback must respond to #callbacks" unless callback.respond_to? :callbacks

    callback.callbacks.each do |type, callbacks|
      callbacks.each { |cb| add_callback! type, [], cb }
    end
  elsif block.arity.zero?
    instance_eval(&block)
  else
    yield self
  end
end