Module: Yes::Core::Aggregate::Draftable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Yes::Core::Aggregate
- Defined in:
- lib/yes/core/aggregate/draftable.rb
Overview
Provides draftable functionality for aggregates
Instance Method Summary collapse
-
#draft? ⇒ Boolean
Checks if this instance is a draft.
-
#read_model ⇒ ApplicationRecord
Override read_model to return changes read model when initialized as draft.
-
#update_read_model(attributes) ⇒ Boolean
Updates the read model and handles draft aggregate updates.
Instance Method Details
#draft? ⇒ Boolean
Checks if this instance is a draft
158 159 160 |
# File 'lib/yes/core/aggregate/draftable.rb', line 158 def draft? @draft == true end |
#read_model ⇒ ApplicationRecord
Override read_model to return changes read model when initialized as draft
137 138 139 140 141 |
# File 'lib/yes/core/aggregate/draftable.rb', line 137 def read_model return super unless draft? && self.class.draftable? @read_model ||= changes_read_model_class.find_or_create_by(id:) end |
#update_read_model(attributes) ⇒ Boolean
Updates the read model and handles draft aggregate updates
147 148 149 150 151 152 153 |
# File 'lib/yes/core/aggregate/draftable.rb', line 147 def update_read_model(attributes) result = super update_draft_aggregate if self.class.draftable? && draft? result end |