module Pakyow::Support::Hookable::ClassMethods

Class-level api methods.

Attributes

__hook_pipeline[R]

Public Class Methods

extended(base) click to toggle source
# File lib/pakyow/support/hookable.rb, line 72
def self.extended(base)
  base.extend(CommonMethods)
end

Public Instance Methods

after(event, name = nil, priority: PRIORITIES[:default], exec: true, &block) click to toggle source

Defines a hook to call after event occurs.

@see before

# File lib/pakyow/support/hookable.rb, line 102
def after(event, name = nil, priority: PRIORITIES[:default], exec: true, &block)
  add_hook(:after, event, name, priority, exec, block)
end
around(event, name = nil, priority: PRIORITIES[:default], exec: true, &block) click to toggle source

Defines a hook to call before and after event occurs.

@see before

# File lib/pakyow/support/hookable.rb, line 110
def around(event, name = nil, priority: PRIORITIES[:default], exec: true, &block)
  add_hook(:before, event, name, priority, exec, block)
  add_hook(:after, event, name, priority, exec, block)
end
before(event, name = nil, priority: PRIORITIES[:default], exec: true, &block) click to toggle source

Defines a hook to call before event occurs.

@param event [Symbol] The name of the event. @param priority [Symbol, Integer] The priority of the hook.

Other priorities include:
  high (1)
  low (-1)
# File lib/pakyow/support/hookable.rb, line 93
def before(event, name = nil, priority: PRIORITIES[:default], exec: true, &block)
  add_hook(:before, event, name, priority, exec, block)
end
Also aliased as: on
events(*events) click to toggle source

Sets the known events for the hookable object. Hooks registered for an event that doesn't exist will raise an ArgumentError.

@param events [Array<Symbol>] The list of known events.

# File lib/pakyow/support/hookable.rb, line 81
def events(*events)
  @__events.concat(events.map(&:to_sym)).uniq!; @__events
end
known_event?(event) click to toggle source

@api private

# File lib/pakyow/support/hookable.rb, line 116
def known_event?(event)
  @__events.include?(event.to_sym)
end
known_hook?(event) click to toggle source
# File lib/pakyow/support/hookable.rb, line 120
def known_hook?(event)
  @__hooks.any? { |hook|
    hook[:name] == event.to_sym
  }
end
on(event, name = nil, priority: PRIORITIES[:default], exec: true, &block)
Alias for: before