class AggregateRoot::InstrumentedRepository

Attributes

instrumentation[R]
repository[R]

Public Class Methods

new(repository, instrumentation) click to toggle source
# File lib/aggregate_root/instrumented_repository.rb, line 7
def initialize(repository, instrumentation)
  @repository = repository
  @instrumentation = instrumentation
end

Public Instance Methods

load(aggregate, stream_name) click to toggle source
# File lib/aggregate_root/instrumented_repository.rb, line 12
def load(aggregate, stream_name)
  instrumentation.instrument("load.repository.aggregate_root",
    aggregate: aggregate,
    stream:    stream_name) do
    repository.load(aggregate, stream_name)
  end
end
method_missing(method_name, *arguments, &block) click to toggle source
Calls superclass method
# File lib/aggregate_root/instrumented_repository.rb, line 35
               def method_missing(method_name, *arguments, &block)
  if respond_to?(method_name)
    repository.public_send(method_name, *arguments, &block)
  else
    super
  end
end
respond_to_missing?(method_name, _include_private) click to toggle source
# File lib/aggregate_root/instrumented_repository.rb, line 43
def respond_to_missing?(method_name, _include_private)
  repository.respond_to?(method_name)
end
store(aggregate, stream_name) click to toggle source
# File lib/aggregate_root/instrumented_repository.rb, line 20
def store(aggregate, stream_name)
  instrumentation.instrument("store.repository.aggregate_root",
    aggregate:     aggregate,
    version:       aggregate.version,
    stored_events: aggregate.unpublished_events.to_a,
    stream:        stream_name) do
    repository.store(aggregate, stream_name)
  end
end
with_aggregate(aggregate, stream_name, &block) click to toggle source
# File lib/aggregate_root/instrumented_repository.rb, line 30
def with_aggregate(aggregate, stream_name, &block)
  block.call(load(aggregate, stream_name))
  store(aggregate, stream_name)
end