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.
-
#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.
39 40 41 42 43 44 45 |
# File 'lib/sandthorn_driver_sequel/access/aggregate_access.rb', line 39 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 |
#find(id) ⇒ Object
Find by database table id.
22 23 24 |
# File 'lib/sandthorn_driver_sequel/access/aggregate_access.rb', line 22 def find(id) storage.aggregates[id] end |
#find_by_aggregate_id(aggregate_id) ⇒ Object
26 27 28 |
# File 'lib/sandthorn_driver_sequel/access/aggregate_access.rb', line 26 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.
31 32 33 34 35 |
# File 'lib/sandthorn_driver_sequel/access/aggregate_access.rb', line 31 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
6 7 8 9 10 11 12 |
# File 'lib/sandthorn_driver_sequel/access/aggregate_access.rb', line 6 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.
16 17 18 19 |
# File 'lib/sandthorn_driver_sequel/access/aggregate_access.rb', line 16 def register_aggregate(aggregate_id, aggregate_type) id = storage.aggregates.insert(aggregate_id: aggregate_id, aggregate_type: aggregate_type.to_s) find(id) end |