Skip to content
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

RubyEventStore::Event constructor should not implicitly convert data attribute to Hash #395

Closed
paneq opened this issue Jul 9, 2018 · 1 comment
Assignees

Comments

@paneq
Copy link
Member

paneq commented Jul 9, 2018

I see no value in that behavior:

  class Event
    def initialize(event_id: SecureRandom.uuid, metadata: nil, data: nil)
      @event_id = event_id.to_s
      @metadata = Metadata.new(metadata.to_h)
      @data     = data.to_h
    end

Let's say you want to use ClosedStruct or Struct or OpenStruct or event a String as data. You also configured a mapper/serializer in a way which knows how to handle such classes an how to serializer/deserialize them properly. Why should RES enforce it to be a Hash? Why can it not be anything else?

The impact should be minimal in my opinion:

  • the documentation shows Hashes
  • the user can wrap mapper with one that does to_h conversion
  • the user can add to_h calls in all places which instantiate events
  • the user can use its own class inheritance to add to_h conversion and call super with modified arguments.
@mpraglowski mpraglowski added this to the 1.0.0 milestone Jul 31, 2018
fidel added a commit that referenced this issue Oct 26, 2018
This allows putting anything as data, eg. nil, Array, Struct, etc.

However, we added {} as a default value for the data to prevent breaking
applications relying on data being hash and using methods like [] or
fetch.

[#395]
@fidel
Copy link
Contributor

fidel commented Oct 26, 2018

Discuss: #480

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants