Class: Low::Event
- Inherits:
-
Object
- Object
- Low::Event
- Includes:
- Support::ValueObject, LowType
- Defined in:
- lib/events/event.rb
Overview
An event represents what is currently happening in your application.
Events are mutable in most cases (except for RenderEvent). They are action-driven, representing inputs and outputs that are currently happening in a linear pipeline-like flow. They are present-tense and one-to-many with one return value. The result of the previous event is made available to the next event. [UNRELEASED]
Integrations:
-
Observers for observer pattern via an event-centric API
-
EventPool for a tree of events and their child events
-
LowState for state machines to trigger multiple actions [UNLRELEASED]
Direct Known Subclasses
Low::Events::RequestEvent, Low::Events::ResponseEvent, Low::Events::StatusEvent
Constant Summary collapse
- ROOT_FIBER =
Fiber.current
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#children ⇒ Object
Returns the value of attribute children.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(key:, action: nil, children: []) ⇒ Event
constructor
A new instance of Event.
- #take ⇒ Object
- #trigger ⇒ Object
Methods included from Support::ValueObject
Constructor Details
#initialize(key:, action: nil, children: []) ⇒ Event
Returns a new instance of Event.
26 27 28 29 30 31 |
# File 'lib/events/event.rb', line 26 def initialize(key:, action: nil, children: []) @key = key @action = action @children = children @created_at = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
21 22 23 |
# File 'lib/events/event.rb', line 21 def action @action end |
#children ⇒ Object
Returns the value of attribute children.
22 23 24 |
# File 'lib/events/event.rb', line 22 def children @children end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
21 22 23 |
# File 'lib/events/event.rb', line 21 def created_at @created_at end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
21 22 23 |
# File 'lib/events/event.rb', line 21 def key @key end |
Class Method Details
.inherited(child) ⇒ Object
68 69 70 |
# File 'lib/events/event.rb', line 68 def inherited(child) child.include LowType end |
.take(**kwargs) ⇒ Object
64 65 66 |
# File 'lib/events/event.rb', line 64 def take(**kwargs) new(**kwargs).take end |
.trigger(**kwargs) ⇒ Object
60 61 62 |
# File 'lib/events/event.rb', line 60 def trigger(**kwargs) new(**kwargs).trigger end |
Instance Method Details
#take ⇒ Object
39 40 41 42 43 |
# File 'lib/events/event.rb', line 39 def take event_tree = branch key = Observers::Keys[@key] || raise(Observers::Keys::MissingKeyError) key.take(event: self) { restore_level(event_tree:) } end |
#trigger ⇒ Object
33 34 35 36 37 |
# File 'lib/events/event.rb', line 33 def trigger event_tree = branch key = Observers::Keys[@key] || raise(Observers::Keys::MissingKeyError) key.trigger(event: self) { restore_level(event_tree:) } end |