Class: AggregateRoot::InstrumentedRepository
- Inherits:
-
Object
- Object
- AggregateRoot::InstrumentedRepository
show all
- Defined in:
- lib/aggregate_root/instrumented_repository.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of InstrumentedRepository.
6
7
8
9
10
|
# File 'lib/aggregate_root/instrumented_repository.rb', line 6
def initialize(repository, instrumentation)
@repository = repository
@instrumentation = instrumentation
self.error_handler = method(:handle_error) if respond_to?(:error_handler=)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, **keyword_arguments, &block) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/aggregate_root/instrumented_repository.rb', line 33
def method_missing(method_name, *arguments, **keyword_arguments, &block)
if respond_to?(method_name)
repository.public_send(method_name, *arguments, **keyword_arguments, &block)
else
super
end
end
|
Instance Method Details
#load(aggregate, stream_name) ⇒ Object
12
13
14
15
16
|
# 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
|
#respond_to_missing?(method_name, _include_private) ⇒ Boolean
41
42
43
|
# File 'lib/aggregate_root/instrumented_repository.rb', line 41
def respond_to_missing?(method_name, _include_private)
repository.respond_to?(method_name)
end
|
#store(aggregate, stream_name) ⇒ Object
18
19
20
21
22
23
24
25
26
|
# File 'lib/aggregate_root/instrumented_repository.rb', line 18
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
) { repository.store(aggregate, stream_name) }
end
|
#with_aggregate(aggregate, stream_name, &block) ⇒ Object
28
29
30
31
|
# File 'lib/aggregate_root/instrumented_repository.rb', line 28
def with_aggregate(aggregate, stream_name, &block)
block.call(load(aggregate, stream_name))
store(aggregate, stream_name)
end
|