class Synapse::Repository::SimpleRepository

Simple repository that works with all sorts of different object mappers, including:

The only requirement of the model is that it properly increment the version field upon save

Public Class Methods

new(lock_manager, aggregate_type) click to toggle source

@param [LockManager] lock_manager @param [Class] aggregate_type @return [undefined]

Calls superclass method
# File lib/synapse/repository/simple_repository.rb, line 15
def initialize(lock_manager, aggregate_type)
  super lock_manager
  @aggregate_type = aggregate_type
end

Protected Instance Methods

aggregate_type() click to toggle source

@return [Class]

# File lib/synapse/repository/simple_repository.rb, line 44
def aggregate_type
  @aggregate_type
end
delete_aggregate_with_lock(aggregate) click to toggle source

@param [AggregateRoot] aggregate @return [undefined]

# File lib/synapse/repository/simple_repository.rb, line 50
def delete_aggregate_with_lock(aggregate)
  aggregate.destroy
end
perform_load(aggregate_id, expected_version) click to toggle source

@raise [AggregateNotFoundError]

If the aggregate with the given identifier could not be found

@raise [ConflictingModificationError]

If the expected version doesn't match the aggregate's actual version

@param [Object] aggregate_id @param [Integer] expected_version @return [AggregateRoot]

# File lib/synapse/repository/simple_repository.rb, line 29
def perform_load(aggregate_id, expected_version)
  # Most ORMs that I can think of use #find like this -- no need for orm_adapter or anything
  # crazy like that
  aggregate = @aggregate_type.find aggregate_id

  unless aggregate
    raise AggregateNotFoundError
  end

  assert_version_expected aggregate, expected_version

  aggregate
end
save_aggregate_with_lock(aggregate) click to toggle source

@param [AggregateRoot] aggregate @return [undefined]

# File lib/synapse/repository/simple_repository.rb, line 56
def save_aggregate_with_lock(aggregate)
  aggregate.save
end