Module: Pakyow::Support::Hookable::ClassMethods

Defined in:
lib/pakyow/support/hookable.rb

Overview

Class-level api methods.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#__hook_pipelineObject (readonly)

Returns the value of attribute __hook_pipeline.



70
71
72
# File 'lib/pakyow/support/hookable.rb', line 70

def __hook_pipeline
  @__hook_pipeline
end

Class Method Details

.extended(base) ⇒ Object



72
73
74
# File 'lib/pakyow/support/hookable.rb', line 72

def self.extended(base)
  base.extend(CommonMethods)
end

Instance Method Details

#after(event, name = nil, priority: , exec: true, &block) ⇒ Object

Defines a hook to call after event occurs.

See Also:



102
103
104
# 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: , exec: true, &block) ⇒ Object

Defines a hook to call before and after event occurs.

See Also:



110
111
112
113
# 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: , exec: true, &block) ⇒ Object Also known as: on

Defines a hook to call before event occurs.

Parameters:

  • event (Symbol)

    The name of the event.

  • priority (Symbol, Integer) (defaults to: )

    The priority of the hook. Other priorities include:

    high (1)
    low (-1)
    


93
94
95
# 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

#events(*events) ⇒ Object

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

Parameters:

  • events (Array<Symbol>)

    The list of known events.



81
82
83
# File 'lib/pakyow/support/hookable.rb', line 81

def events(*events)
  @__events.concat(events.map(&:to_sym)).uniq!; @__events
end

#known_event?(event) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


116
117
118
# File 'lib/pakyow/support/hookable.rb', line 116

def known_event?(event)
  @__events.include?(event.to_sym)
end

#known_hook?(event) ⇒ Boolean

Returns:

  • (Boolean)


120
121
122
123
124
# File 'lib/pakyow/support/hookable.rb', line 120

def known_hook?(event)
  @__hooks.any? { |hook|
    hook[:name] == event.to_sym
  }
end