Skip to content

Commit

Permalink
Use descriptor name instead of class name
Browse files Browse the repository at this point in the history
res_testing.OrderCreated instead of ResTesting::OrderCreated,
this is less ruby-related and more protobuf oriented. If that descriptor
name is used throught many apps, it should be easier to handle it
compared to ruby classes.

Issue: #228
  • Loading branch information
paneq committed Mar 30, 2018
1 parent 014ca7d commit b005838
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rails_event_store/spec/protobuf_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module RailsEventStore
client = Client.new(repository: RailsEventStoreActiveRecord::EventRepository.new(
mapper: RubyEventStore::Mappers::Protobuf.new,
))
client.subscribe(->(ev){@ev = ev}, [ResTesting::OrderCreated])
client.subscribe(->(ev){@ev = ev}, [ResTesting::OrderCreated.descriptor.name])
event = RubyEventStore::Proto.new(
data: ResTesting::OrderCreated.new(
customer_id: 123,
Expand Down
4 changes: 2 additions & 2 deletions ruby_event_store/lib/ruby_event_store/mappers/protobuf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(event_id: SecureRandom.uuid, metadata: nil, data: nil)
end

def type
data.class.name
data.class.descriptor.name
end
end

Expand All @@ -29,7 +29,7 @@ def event_to_serialized_record(domain_event)

def serialized_record_to_event(record)
event_type = events_class_remapping.fetch(record.event_type) { record.event_type }
data = Object.const_get(event_type).decode(record.data)
data = Google::Protobuf::DescriptorPool.generated_pool.lookup(event_type).msgclass.decode(record.data)
Proto.new(
event_id: record.event_id,
data: data,
Expand Down

0 comments on commit b005838

Please sign in to comment.