Class: SandthornDriverSequel::AggregateAccess
- Inherits:
-
SandthornDriverSequel::Access::Base
- Object
- SandthornDriverSequel::Access::Base
- SandthornDriverSequel::AggregateAccess
- Defined in:
- lib/sandthorn_driver_sequel/access/aggregate_access.rb
Instance Method Summary collapse
-
#aggregate_ids(aggregate_type: nil) ⇒ Object
Returns aggregate ids.
- #aggregate_types ⇒ Object
-
#find(id) ⇒ Object
Find by database table id.
- #find_by_aggregate_id(aggregate_id) ⇒ Object
-
#find_by_aggregate_id!(aggregate_id) ⇒ Object
Throws an error if the aggregate isn’t registered.
- #find_or_register(aggregate_id, aggregate_type) ⇒ Object
-
#register_aggregate(aggregate_id, aggregate_type) ⇒ Object
Create a database row for an aggregate.
Methods inherited from SandthornDriverSequel::Access::Base
Constructor Details
This class inherits a constructor from SandthornDriverSequel::Access::Base
Instance Method Details
#aggregate_ids(aggregate_type: nil) ⇒ Object
Returns aggregate ids.
41 42 43 44 45 46 47 |
# File 'lib/sandthorn_driver_sequel/access/aggregate_access.rb', line 41 def aggregate_ids(aggregate_type: nil) aggs = storage.aggregates if aggregate_type aggs = aggs.where(aggregate_type: aggregate_type.to_s) end aggs.order(:id).select_map(:aggregate_id) end |
#aggregate_types ⇒ Object
35 36 37 |
# File 'lib/sandthorn_driver_sequel/access/aggregate_access.rb', line 35 def aggregate_types storage.aggregates.select(:aggregate_type).distinct.select_map(:aggregate_type) end |
#find(id) ⇒ Object
Find by database table id.
20 21 22 |
# File 'lib/sandthorn_driver_sequel/access/aggregate_access.rb', line 20 def find(id) storage.aggregates[id] end |
#find_by_aggregate_id(aggregate_id) ⇒ Object
24 25 26 |
# File 'lib/sandthorn_driver_sequel/access/aggregate_access.rb', line 24 def find_by_aggregate_id(aggregate_id) storage.aggregates.first(aggregate_id: aggregate_id) end |
#find_by_aggregate_id!(aggregate_id) ⇒ Object
Throws an error if the aggregate isn’t registered.
29 30 31 32 33 |
# File 'lib/sandthorn_driver_sequel/access/aggregate_access.rb', line 29 def find_by_aggregate_id!(aggregate_id) aggregate = find_by_aggregate_id(aggregate_id) raise Errors::NoAggregateError, aggregate_id unless aggregate aggregate end |
#find_or_register(aggregate_id, aggregate_type) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/sandthorn_driver_sequel/access/aggregate_access.rb', line 4 def find_or_register(aggregate_id, aggregate_type) if aggregate = find_by_aggregate_id(aggregate_id) aggregate else register_aggregate(aggregate_id, aggregate_type) end end |
#register_aggregate(aggregate_id, aggregate_type) ⇒ Object
Create a database row for an aggregate. Return the row.
14 15 16 17 |
# File 'lib/sandthorn_driver_sequel/access/aggregate_access.rb', line 14 def register_aggregate(aggregate_id, aggregate_type) id = storage.aggregates.insert(aggregate_id: aggregate_id, aggregate_type: aggregate_type.to_s) find(id) end |