Class: ActiveProjection::CachedProjectionRepository
- Inherits:
-
Object
- Object
- ActiveProjection::CachedProjectionRepository
- Defined in:
- app/models/active_projection/cached_projection_repository.rb
Overview
This implements a fully cached projection repository.
notice: NOT thread safe!
Class Method Summary collapse
- .ensure_exists(projection_class) ⇒ Object
- .ensure_solid(projection_class) ⇒ Object
- .get_all_broken ⇒ Object
- .get_last_id(id) ⇒ Object
- .last_ids ⇒ Object
- .set_broken(id) ⇒ Object
- .set_last_id(id, last_id) ⇒ Object
- .solid?(id) ⇒ Boolean
Class Method Details
.ensure_exists(projection_class) ⇒ Object
31 32 33 34 35 36 |
# File 'app/models/active_projection/cached_projection_repository.rb', line 31 def self.ensure_exists(projection_class) Projection.transaction do projection = Projection.find_or_create_by! class_name: projection_class projections[projection.id] = projection end end |
.ensure_solid(projection_class) ⇒ Object
38 39 40 41 42 43 44 |
# File 'app/models/active_projection/cached_projection_repository.rb', line 38 def self.ensure_solid(projection_class) Projection.transaction do projection = Projection.find_or_initialize_by class_name: projection_class projection.update! solid: true projections[projection.id] = projection end end |
.get_all_broken ⇒ Object
23 24 25 |
# File 'app/models/active_projection/cached_projection_repository.rb', line 23 def self.get_all_broken projections.values.reject(&:solid).map(&:class_name) end |
.get_last_id(id) ⇒ Object
11 12 13 |
# File 'app/models/active_projection/cached_projection_repository.rb', line 11 def self.get_last_id(id) projections[id].last_id end |
.last_ids ⇒ Object
7 8 9 |
# File 'app/models/active_projection/cached_projection_repository.rb', line 7 def self.last_ids projections.values.map(&:last_id) end |
.set_broken(id) ⇒ Object
19 20 21 |
# File 'app/models/active_projection/cached_projection_repository.rb', line 19 def self.set_broken(id) projections[id].update! solid: false end |
.set_last_id(id, last_id) ⇒ Object
15 16 17 |
# File 'app/models/active_projection/cached_projection_repository.rb', line 15 def self.set_last_id(id, last_id) projections[id].update! last_id: last_id end |
.solid?(id) ⇒ Boolean
27 28 29 |
# File 'app/models/active_projection/cached_projection_repository.rb', line 27 def self.solid?(id) projections[id].solid end |