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

Examples:

Include in an aggregate

class UserAggregate < Yes::Core::Aggregate
  draftable
end

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#draft?Boolean

Checks if this instance is a draft

Returns:

  • (Boolean)

    true if draft, false otherwise

Since:

  • 0.1.0



158
159
160
# File 'lib/yes/core/aggregate/draftable.rb', line 158

def draft?
  @draft == true
end

#read_modelApplicationRecord

Override read_model to return changes read model when initialized as draft

Returns:

Since:

  • 0.1.0



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

Parameters:

  • attributes (Hash)

    The attributes to update

Returns:

  • (Boolean)

    true if successful

Since:

  • 0.1.0



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