Class: Low::Event
- Inherits:
-
Object
- Object
- Low::Event
- Includes:
- Low::Events::Definable, Support::ValueObject, LowType, Observers
- Defined in:
- lib/interfaces/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 which we wrap in 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
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
The subclass will provide the key, usually “self.class”.
- #take ⇒ Object
- #trigger ⇒ Object
Methods included from Support::ValueObject
Methods included from Low::Events::Definable
Constructor Details
#initialize(key:, action: nil, children: []) ⇒ Event
The subclass will provide the key, usually “self.class”.
29 30 31 32 33 34 |
# File 'lib/interfaces/event.rb', line 29 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.
25 26 27 |
# File 'lib/interfaces/event.rb', line 25 def action @action end |
#children ⇒ Object
Returns the value of attribute children.
26 27 28 |
# File 'lib/interfaces/event.rb', line 26 def children @children end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
25 26 27 |
# File 'lib/interfaces/event.rb', line 25 def created_at @created_at end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
25 26 27 |
# File 'lib/interfaces/event.rb', line 25 def key @key end |
Class Method Details
.inherited(child) ⇒ Object
52 53 54 |
# File 'lib/interfaces/event.rb', line 52 def inherited(child) child.include LowType end |
.take(**kwargs) ⇒ Object
50 |
# File 'lib/interfaces/event.rb', line 50 def take(**kwargs) = new(**kwargs).take |
.trigger(**kwargs) ⇒ Object
49 |
# File 'lib/interfaces/event.rb', line 49 def trigger(**kwargs) = new(**kwargs).trigger |
Instance Method Details
#take ⇒ Object
42 43 44 45 46 |
# File 'lib/interfaces/event.rb', line 42 def take event_tree = branch key = Observers::Keys[@key] key.take(event: self) { restore_level(event_tree:) } end |
#trigger ⇒ Object
36 37 38 39 40 |
# File 'lib/interfaces/event.rb', line 36 def trigger event_tree = branch key = Observers::Keys[@key] key.trigger(event: self) { restore_level(event_tree:) } end |