-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserve types transform #1103
Preserve types transform #1103
Conversation
ruby_event_store/lib/ruby_event_store/mappers/transformation/preserve_types.rb
Show resolved
Hide resolved
ruby_event_store/lib/ruby_event_store/mappers/transformation/preserve_types.rb
Outdated
Show resolved
Hide resolved
ruby_event_store/lib/ruby_event_store/mappers/transformation/preserve_types.rb
Outdated
Show resolved
Hide resolved
ruby_event_store/lib/ruby_event_store/mappers/transformation/preserve_types.rb
Outdated
Show resolved
Hide resolved
ruby_event_store/lib/ruby_event_store/mappers/transformation/preserve_types.rb
Outdated
Show resolved
Hide resolved
I like that 👍 |
00222dc
to
f15b5ff
Compare
ruby_event_store/lib/ruby_event_store/mappers/transformation/preserve_types.rb
Outdated
Show resolved
Hide resolved
def dump(record) | ||
data = transform(record.data) | ||
metadata = transform(record.metadata) | ||
if (metadata.respond_to?(:[])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make an assumption on Metadata being always in an Event?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With RubyEventStore::Event
this assumption is always true because of its initializer implementation
def initialize(event_id: SecureRandom.uuid, metadata: nil, data: {})
@event_id = event_id.to_s
@metadata = Metadata.new(metadata.to_h)
@data = data
end
If we prepare event with nil metadata (or use another event class that allows that) we will get:
> e = RubyEventStore::Event.new
=> #<RubyEventStore::Event:0x00007fc630389408 @event_id="2755b447-78d1-4dad-aec3-29792a9b6567", @metad...
> e.metadata
=> #<RubyEventStore::Metadata:0x00007fc630388eb8 @h={}>
> e.instance_variable_set("@metadata", nil)
=> nil
> e.metadata
=> nil
> c = RubyEventStore::Client.new(repository: RubyEventStore::InMemoryRepository.new)
=> #<RubyEventStore::Client:0xb4>
> c.publish(e)
Traceback (most recent call last):
9: from /Users/mpraglowski/.rbenv/versions/2.7.2/bin/irb:23:in `<main>'
8: from /Users/mpraglowski/.rbenv/versions/2.7.2/bin/irb:23:in `load'
7: from /Users/mpraglowski/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
6: from (irb):13
5: from /Users/mpraglowski/arkency/rails_event_store/ruby_event_store/lib/ruby_event_store/client.rb:32:in `publish'
4: from /Users/mpraglowski/arkency/rails_event_store/ruby_event_store/lib/ruby_event_store/client.rb:341:in `enrich_events_metadata'
3: from /Users/mpraglowski/arkency/rails_event_store/ruby_event_store/lib/ruby_event_store/client.rb:341:in `each'
2: from /Users/mpraglowski/arkency/rails_event_store/ruby_event_store/lib/ruby_event_store/client.rb:341:in `block in enrich_events_metadata'
1: from /Users/mpraglowski/arkency/rails_event_store/ruby_event_store/lib/ruby_event_store/client.rb:347:in `enrich_event_metadata'
NoMethodError (undefined method `[]' for nil:NilClass)
So here in transformations I could assume metadata are present. The question is if I should make such assumptions for both data & metadata ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW this works because:
> nil.respond_to?(:[])
=> false
91af5aa
to
4ec73f4
Compare
Timestamps and simple value objects (RequestUuid, UserAgent or just DateTime objects) may exist there too
…be passed as dependency One could pass its own to redefine serializers map if needed (i.e. in another BC)
Avoid fails while in different timezones
… reserved keywords, anything could be hash keys
4ec73f4
to
b58a4bb
Compare
No description provided.