class SandthornDriverSequel::AggregateAccess

Public Instance Methods

aggregate_ids(aggregate_type: nil) click to toggle source

Returns aggregate ids. @param aggregate_type, optional,

# 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) click to toggle source

Find by database table id.

# File lib/sandthorn_driver_sequel/access/aggregate_access.rb, line 22
def find(id)
  storage.aggregates[id]
end
find_by_aggregate_id(aggregate_id) click to toggle source
# 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) click to toggle source

Throws an error if the aggregate isn't registered.

# 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) click to toggle source
# 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) click to toggle source

Create a database row for an aggregate. Return the row.

# 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