Class: Yes::Core::ProcessManagers::State Abstract
- Inherits:
-
Object
- Object
- Yes::Core::ProcessManagers::State
- Defined in:
- lib/yes/core/process_managers/state.rb
Overview
This class is abstract.
Subclass and override #stream, #required_attributes, and implement apply_* methods.
Represents the state of a subject loaded in a process manager by replaying events.
Class Method Summary collapse
-
.load(id) ⇒ State
Loads the state for a given ID.
Instance Method Summary collapse
-
#initialize(id) ⇒ State
constructor
A new instance of State.
-
#load ⇒ void
Loads the state from relevant events.
-
#valid? ⇒ Boolean
Checks if the state is valid (all required attributes are present).
Constructor Details
#initialize(id) ⇒ State
Returns a new instance of State.
41 42 43 |
# File 'lib/yes/core/process_managers/state.rb', line 41 def initialize(id) @id = id end |
Class Method Details
.load(id) ⇒ State
Loads the state for a given ID.
36 37 38 |
# File 'lib/yes/core/process_managers/state.rb', line 36 def self.load(id) new(id).tap(&:load) end |
Instance Method Details
#load ⇒ void
This method returns an undefined value.
Loads the state from relevant events.
48 49 50 51 52 53 |
# File 'lib/yes/core/process_managers/state.rb', line 48 def load events = relevant_events(stream) return unless events process_events(events) end |
#valid? ⇒ Boolean
Checks if the state is valid (all required attributes are present).
58 59 60 |
# File 'lib/yes/core/process_managers/state.rb', line 58 def valid? required_attributes.all? { |attr| send(attr).present? } end |