Class: Core::Event::Callable

Inherits:
Object
  • Object
show all
Includes:
Is::Inspectable
Defined in:
lib/core/event/callable.rb

Overview

public

Manages and calls an event pipeline.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Callable

Returns a new instance of Callable.



17
18
19
20
21
22
# File 'lib/core/event/callable.rb', line 17

def initialize(object)
  @object = object
  @mutex = Mutex.new
  @events = []
  @pipelines = {}
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



24
25
26
# File 'lib/core/event/callable.rb', line 24

def events
  @events
end

#pipelinesObject (readonly)

Returns the value of attribute pipelines.



25
26
27
# File 'lib/core/event/callable.rb', line 25

def pipelines
  @pipelines
end

Instance Method Details

#callback(*during, before: [], after: [], method: nil, context: nil, &block) ⇒ Object

public

Defines a callback to be called during, before, and/or after the given events.



37
38
39
40
41
# File 'lib/core/event/callable.rb', line 37

def callback(*during, before: [], after: [], method: nil, context: nil, &block)
  define_callback(:before, *before, method: method, context: context, &block)
  define_callback(:during, *during, method: method, context: context, &block)
  define_callback(:after, *after, method: method, context: context, &block)
end

#finished(object, event) ⇒ Object

public

Calls after callbacks for the given event with the given arguments.



73
74
75
# File 'lib/core/event/callable.rb', line 73

def finished(object, event, ...)
  compile.finished(object, event, ...)
end

#performing(object, event) ⇒ Object

public

Calls callbacks for the given event with the given arguments.



61
62
63
# File 'lib/core/event/callable.rb', line 61

def performing(object, event, ...)
  compile.performing(object, event, ...)
end

#register(*events) ⇒ Object

public

Registers one or more events by name.



29
30
31
32
33
# File 'lib/core/event/callable.rb', line 29

def register(*events)
  @mutex.synchronize do
    @events.concat(events.map(&:to_sym)).uniq!
  end
end

#starting(object, event) ⇒ Object

public

Calls before callbacks for the given event with the given arguments.



67
68
69
# File 'lib/core/event/callable.rb', line 67

def starting(object, event, ...)
  compile.starting(object, event, ...)
end