Class: Core::Event::Callable
- Inherits:
-
Object
- Object
- Core::Event::Callable
- Includes:
- Is::Inspectable
- Defined in:
- lib/core/event/callable.rb
Overview
- public
-
Manages and calls an event pipeline.
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#pipelines ⇒ Object
readonly
Returns the value of attribute pipelines.
Instance Method Summary collapse
-
#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.
-
#finalize ⇒ Object
[public].
-
#finished(object, event) ⇒ Object
- public
-
Calls after callbacks for the given event with the given arguments.
-
#initialize(object) ⇒ Callable
constructor
A new instance of Callable.
- #initialize_copy ⇒ Object
-
#performing(object, event) ⇒ Object
- public
-
Calls callbacks for the given event with the given arguments.
-
#register(*events) ⇒ Object
- public
-
Registers one or more events by name.
-
#relocate(object) ⇒ Object
- public
-
Relocates to another object context.
-
#starting(object, event) ⇒ Object
- public
-
Calls before callbacks for the given event with the given arguments.
Constructor Details
#initialize(object) ⇒ Callable
Returns a new instance of Callable.
17 18 19 20 21 22 23 |
# File 'lib/core/event/callable.rb', line 17 def initialize(object) @object = object @mutex = Mutex.new @events = [] @pipelines = {} @compiled = false end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
35 36 37 |
# File 'lib/core/event/callable.rb', line 35 def events @events end |
#pipelines ⇒ Object (readonly)
Returns the value of attribute pipelines.
36 37 38 |
# File 'lib/core/event/callable.rb', line 36 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.
60 61 62 63 64 |
# File 'lib/core/event/callable.rb', line 60 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 |
#finalize ⇒ Object
- public
102 103 104 105 106 |
# File 'lib/core/event/callable.rb', line 102 def finalize compile self end |
#finished(object, event) ⇒ Object
- public
-
Calls after callbacks for the given event with the given arguments.
96 97 98 |
# File 'lib/core/event/callable.rb', line 96 def finished(object, event, ...) finalize.finished(object, event, ...) end |
#initialize_copy ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/core/event/callable.rb', line 25 def initialize_copy(...) @pipelines = @pipelines.each_pair.each_with_object({}) { |(event, pipelines), pipelines_hash| pipelines_hash[event] = pipelines.each_pair.each_with_object({}) { |(type, pipeline), events_hash| events_hash[type] = pipeline.clone } } super end |
#performing(object, event) ⇒ Object
- public
-
Calls callbacks for the given event with the given arguments.
84 85 86 |
# File 'lib/core/event/callable.rb', line 84 def performing(object, event, ...) finalize.performing(object, event, ...) end |
#register(*events) ⇒ Object
- public
-
Registers one or more events by name.
52 53 54 55 56 |
# File 'lib/core/event/callable.rb', line 52 def register(*events) @mutex.synchronize do @events.concat(events.map(&:to_sym)).uniq! end end |
#relocate(object) ⇒ Object
- public
-
Relocates to another object context.
40 41 42 43 44 45 46 47 48 |
# File 'lib/core/event/callable.rb', line 40 def relocate(object) @object = object @pipelines.each_value do |pipelines_hash| pipelines_hash.each_value do |pipeline| pipeline.relocate(object) end end end |
#starting(object, event) ⇒ Object
- public
-
Calls before callbacks for the given event with the given arguments.
90 91 92 |
# File 'lib/core/event/callable.rb', line 90 def starting(object, event, ...) finalize.starting(object, event, ...) end |