Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ def event_in_stream?(event_id, stream)
@repo_reader.event_in_stream?(event_id, stream)
end

def cleaner_inspect(indent: 0)
<<~EOS.chomp
#{' ' * indent}#<#{self.class}:0x#{__id__.to_s(16)}>
#{' ' * indent} - serializer: #{@serializer.inspect}
EOS
end

private

def add_to_stream(event_ids, stream, expected_version)
Expand Down
7 changes: 7 additions & 0 deletions ruby_event_store/lib/ruby_event_store/broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def all_subscriptions_for(topic)
subscriptions.all_for(topic)
end

def cleaner_inspect(indent: 0)
<<~EOS.chomp
#{' ' * indent}#<#{self.class}:0x#{__id__.to_s(16)}>
#{' ' * indent} - dispatcher: #{dispatcher.inspect}
EOS
end

private

attr_reader :dispatcher, :subscriptions
Expand Down
5 changes: 4 additions & 1 deletion ruby_event_store/lib/ruby_event_store/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,10 @@ def overwrite(events_or_event)
end

def inspect
"#<#{self.class}:0x#{__id__.to_s(16)}>"
"#<#{self.class}:0x#{__id__.to_s(16)}>\n" \
" - repository: #{@repository.respond_to?(:cleaner_inspect) ? @repository.cleaner_inspect(indent: 2) : @repository.inspect}\n" \
" - broker: #{@broker.respond_to?(:cleaner_inspect) ? @broker.cleaner_inspect(indent: 2) : @broker.inspect}\n" \
" - mapper: #{@mapper.respond_to?(:cleaner_inspect) ? @mapper.cleaner_inspect(indent: 2) : @mapper.inspect}"
end

EMPTY_HASH = {}.freeze
Expand Down
7 changes: 7 additions & 0 deletions ruby_event_store/lib/ruby_event_store/in_memory_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ def event_in_stream?(event_id, stream)
!streams[stream.name].find { |event_in_stream| event_in_stream.event_id.eql?(event_id) }.nil?
end

def cleaner_inspect(indent: 0)
<<~EOS.chomp
#{' ' * indent}#<#{self.class}:0x#{__id__.to_s(16)}>
#{' ' * indent} - serializer: #{serializer.inspect}
EOS
end

private

def read_scope(spec)
Expand Down
7 changes: 7 additions & 0 deletions ruby_event_store/lib/ruby_event_store/instrumented_broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def respond_to_missing?(method_name, _include_private)
broker.respond_to?(method_name)
end

def cleaner_inspect(indent: 0)
<<~EOS.chomp
#{' ' * indent}#<#{self.class}:0x#{__id__.to_s(16)}>
#{' ' * indent} - broker: #{broker.respond_to?(:cleaner_inspect) ? broker.cleaner_inspect(indent: indent + 2) : broker.inspect}
EOS
end

private

attr_reader :instrumentation, :broker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ def respond_to_missing?(method_name, _include_private)
repository.respond_to?(method_name)
end

def cleaner_inspect(indent: 0)
<<~EOS.chomp
#{' ' * indent}#<#{self.class}:0x#{__id__.to_s(16)}>
#{' ' * indent} - repository: #{repository.respond_to?(:cleaner_inspect) ? repository.cleaner_inspect(indent: indent + 2) : repository.inspect}
EOS
end

private

attr_reader :repository, :instrumentation
Expand Down
7 changes: 7 additions & 0 deletions ruby_event_store/lib/ruby_event_store/mappers/batch_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ def events_to_records(events)
def records_to_events(records)
records.map { |record| @mapper.record_to_event(record) }
end

def cleaner_inspect(indent: 0)
<<~EOS.chomp
#{' ' * indent}#<#{self.class}:0x#{__id__.to_s(16)}>
#{' ' * indent} - mapper: #{@mapper.respond_to?(:cleaner_inspect) ? @mapper.cleaner_inspect(indent: indent + 2) : @mapper.inspect}
EOS
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def records_to_events(records)
end
end

def cleaner_inspect(indent: 0)
<<~EOS.chomp
#{' ' * indent}#<#{self.class}:0x#{__id__.to_s(16)}>
#{' ' * indent} - mapper: #{mapper.respond_to?(:cleaner_inspect) ? mapper.cleaner_inspect(indent: indent + 2) : mapper.inspect}
EOS
end

private

attr_reader :instrumentation, :mapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def record_to_event(record)
end
end

def cleaner_inspect(indent: 0)
<<~EOS.chomp
#{' ' * indent}#<#{self.class}:0x#{__id__.to_s(16)}>
#{' ' * indent} - mapper: #{mapper.respond_to?(:cleaner_inspect) ? mapper.cleaner_inspect(indent: indent + 2) : mapper.inspect}
EOS
end

private

attr_reader :instrumentation, :mapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ def record_to_event(record)
pipeline.load(record)
end

def cleaner_inspect(indent: 0)
transformations_list = pipeline.transformations.map { |t| "#{' ' * (indent + 4)}- #{t.inspect}" }.join("\n")
<<~EOS.chomp
#{' ' * indent}#<#{self.class}:0x#{__id__.to_s(16)}>
#{' ' * indent} - transformations:
#{transformations_list}
EOS
end

private

attr_reader :pipeline
Expand Down
18 changes: 18 additions & 0 deletions ruby_event_store/spec/broker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,23 @@
module RubyEventStore
::RSpec.describe Broker do
it_behaves_like "broker", Broker

specify "#cleaner_inspect" do
broker = Broker.new

expect(broker.cleaner_inspect).to eq(<<~EOS.chomp)
#<RubyEventStore::Broker:0x#{broker.object_id.to_s(16)}>
- dispatcher: #{broker.instance_variable_get(:@dispatcher).inspect}
EOS
end

specify "#cleaner_inspect with indent" do
broker = Broker.new

expect(broker.cleaner_inspect(indent: 4)).to eq(<<~EOS.chomp)
#{' ' * 4}#<RubyEventStore::Broker:0x#{broker.object_id.to_s(16)}>
#{' ' * 4} - dispatcher: #{broker.instance_variable_get(:@dispatcher).inspect}
EOS
end
end
end
10 changes: 9 additions & 1 deletion ruby_event_store/spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,15 @@ def self.event_type

specify "#inspect" do
object_id = client.object_id.to_s(16)
expect(client.inspect).to eq("#<RubyEventStore::Client:0x#{object_id}>")
repository = client.instance_variable_get(:@repository)
broker = client.instance_variable_get(:@broker)
mapper = client.instance_variable_get(:@mapper)
expect(client.inspect).to eq(<<~EOS.chomp)
#<RubyEventStore::Client:0x#{object_id}>
- repository: #{repository.respond_to?(:cleaner_inspect) ? repository.cleaner_inspect(indent: 2) : repository.inspect}
- broker: #{broker.respond_to?(:cleaner_inspect) ? broker.cleaner_inspect(indent: 2) : broker.inspect}
- mapper: #{mapper.respond_to?(:cleaner_inspect) ? mapper.cleaner_inspect(indent: 2) : mapper.inspect}
EOS
end

specify "transform Record to SerializedRecord is only once when using the same serializer" do
Expand Down
14 changes: 14 additions & 0 deletions ruby_event_store/spec/in_memory_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,19 @@ module RubyEventStore
repository.append_to_stream([SRecord.new], Stream.new("stream"), ExpectedVersion.any)
end.not_to raise_error
end

specify "#cleaner_inspect" do
expect(repository.cleaner_inspect).to eq(<<~EOS.chomp)
#<#{repository.class.name}:0x#{repository.object_id.to_s(16)}>
- serializer: #{repository.instance_variable_get(:@serializer).inspect}
EOS
end

specify "#cleaner_inspect with indent" do
expect(repository.cleaner_inspect(indent: 4)).to eq(<<~EOS.chomp)
#{' ' * 4}#<#{repository.class.name}:0x#{repository.object_id.to_s(16)}>
#{' ' * 4} - serializer: #{repository.instance_variable_get(:@serializer).inspect}
EOS
end
end
end
18 changes: 18 additions & 0 deletions ruby_event_store/spec/instrumented_broker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,24 @@ module RubyEventStore
)
end

specify "#cleaner_inspect" do
broker = Broker.new
instrumented_broker = InstrumentedBroker.new(broker, ActiveSupport::Notifications)
expect(instrumented_broker.cleaner_inspect).to eq(<<~EOS.chomp)
#<#{instrumented_broker.class.name}:0x#{instrumented_broker.object_id.to_s(16)}>
- broker: #{broker.cleaner_inspect(indent: 2)}
EOS
end

specify "#cleaner_inspect with indent" do
broker = Broker.new
instrumented_broker = InstrumentedBroker.new(broker, ActiveSupport::Notifications)
expect(instrumented_broker.cleaner_inspect(indent: 4)).to eq(<<~EOS.chomp)
#{' ' * 4}#<#{instrumented_broker.class.name}:0x#{instrumented_broker.object_id.to_s(16)}>
#{' ' * 4} - broker: #{broker.cleaner_inspect(indent: 6)}
EOS
end

def subscribe_to(name)
received_payloads = []
callback = ->(_name, _start, _finish, _id, payload) { received_payloads << payload }
Expand Down
18 changes: 18 additions & 0 deletions ruby_event_store/spec/instrumented_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,24 @@ module RubyEventStore
)
end

specify "#cleaner_inspect" do
repository = InMemoryRepository.new
instrumented_repository = InstrumentedRepository.new(repository, ActiveSupport::Notifications)
expect(instrumented_repository.cleaner_inspect).to eq(<<~EOS.chomp)
#<#{instrumented_repository.class.name}:0x#{instrumented_repository.object_id.to_s(16)}>
- repository: #{repository.cleaner_inspect(indent: 2)}
EOS
end

specify "#cleaner_inspect with indent" do
repository = InMemoryRepository.new
instrumented_repository = InstrumentedRepository.new(repository, ActiveSupport::Notifications)
expect(instrumented_repository.cleaner_inspect(indent: 4)).to eq(<<~EOS.chomp)
#{' ' * 4}#<#{instrumented_repository.class.name}:0x#{instrumented_repository.object_id.to_s(16)}>
#{' ' * 4} - repository: #{repository.cleaner_inspect(indent: 6)}
EOS
end

def subscribe_to(name)
received_payloads = []
callback = ->(_name, _start, _finish, _id, payload) { received_payloads << payload }
Expand Down
16 changes: 16 additions & 0 deletions ruby_event_store/spec/mappers/batch_mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ module Mappers
mapper = BatchMapper.new(item_mapper)
expect(mapper.records_to_events(records)).to eq(records.map(&:event_id))
end

specify "#cleaner_inspect" do
mapper = BatchMapper.new
expect(mapper.cleaner_inspect).to eq(<<~EOS.chomp)
#<#{mapper.class.name}:0x#{mapper.object_id.to_s(16)}>
- mapper: #{mapper.instance_variable_get(:@mapper).cleaner_inspect(indent: 2)}
EOS
end

specify "#cleaner_inspect with indent" do
mapper = BatchMapper.new
expect(mapper.cleaner_inspect(indent: 4)).to eq(<<~EOS.chomp)
#{' ' * 4}#<#{mapper.class.name}:0x#{mapper.object_id.to_s(16)}>
#{' ' * 4} - mapper: #{mapper.instance_variable_get(:@mapper).cleaner_inspect(indent: 6)}
EOS
end
end
end
end
20 changes: 20 additions & 0 deletions ruby_event_store/spec/mappers/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ module Mappers
def stringify(hash)
hash.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v }
end

specify "#cleaner_inspect" do
mapper = Default.new
transformations_list = mapper.instance_variable_get(:@pipeline).transformations.map { |t| " - #{t.inspect}" }.join("\n")
expect(mapper.cleaner_inspect).to eq(<<~EOS.chomp)
#<#{mapper.class.name}:0x#{mapper.object_id.to_s(16)}>
- transformations:
#{transformations_list}
EOS
end

specify "#cleaner_inspect with indent" do
mapper = Default.new
transformations_list = mapper.instance_variable_get(:@pipeline).transformations.map { |t| "#{' ' * 8}- #{t.inspect}" }.join("\n")
expect(mapper.cleaner_inspect(indent: 4)).to eq(<<~EOS.chomp)
#{' ' * 4}#<#{mapper.class.name}:0x#{mapper.object_id.to_s(16)}>
#{' ' * 4} - transformations:
#{transformations_list}
EOS
end
end
end
end
18 changes: 18 additions & 0 deletions ruby_event_store/spec/mappers/instrumented_batch_mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ module Mappers
end
end

specify "#cleaner_inspect" do
mapper = BatchMapper.new
instrumented_mapper = InstrumentedBatchMapper.new(mapper, ActiveSupport::Notifications)
expect(instrumented_mapper.cleaner_inspect).to eq(<<~EOS.chomp)
#<#{instrumented_mapper.class.name}:0x#{instrumented_mapper.object_id.to_s(16)}>
- mapper: #{mapper.cleaner_inspect(indent: 2)}
EOS
end

specify "#cleaner_inspect with indent" do
mapper = BatchMapper.new
instrumented_mapper = InstrumentedBatchMapper.new(mapper, ActiveSupport::Notifications)
expect(instrumented_mapper.cleaner_inspect(indent: 4)).to eq(<<~EOS.chomp)
#{' ' * 4}#<#{instrumented_mapper.class.name}:0x#{instrumented_mapper.object_id.to_s(16)}>
#{' ' * 4} - mapper: #{mapper.cleaner_inspect(indent: 6)}
EOS
end

def subscribe_to(name)
received_payloads = []
callback = ->(_name, _start, _finish, _id, payload) { received_payloads << payload }
Expand Down
18 changes: 18 additions & 0 deletions ruby_event_store/spec/mappers/instrumented_mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ module Mappers
end
end

specify "#cleaner_inspect" do
mapper = Default.new
instrumented_mapper = InstrumentedMapper.new(mapper, ActiveSupport::Notifications)
expect(instrumented_mapper.cleaner_inspect).to eq(<<~EOS.chomp)
#<#{instrumented_mapper.class.name}:0x#{instrumented_mapper.object_id.to_s(16)}>
- mapper: #{mapper.cleaner_inspect(indent: 2)}
EOS
end

specify "#cleaner_inspect with indent" do
mapper = Default.new
instrumented_mapper = InstrumentedMapper.new(mapper, ActiveSupport::Notifications)
expect(instrumented_mapper.cleaner_inspect(indent: 4)).to eq(<<~EOS.chomp)
#{' ' * 4}#<#{instrumented_mapper.class.name}:0x#{instrumented_mapper.object_id.to_s(16)}>
#{' ' * 4} - mapper: #{mapper.cleaner_inspect(indent: 6)}
EOS
end

def subscribe_to(name)
received_payloads = []
callback = ->(_name, _start, _finish, _id, payload) { received_payloads << payload }
Expand Down
Loading