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

Enable to give a hash object to initializer #51

Open
NotFounds opened this issue Dec 27, 2021 · 0 comments
Open

Enable to give a hash object to initializer #51

NotFounds opened this issue Dec 27, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@NotFounds
Copy link

Why

I would often like to create a Pb object from a hash object.
But a hash object does not allow dot access.

What

Add an argument to specify the access policy which uses dot access or symbol access. That uses OpenStruct internally.

e.g.

UserPbSerializer.new({
  id: 1234,
  name: "John Smith"
}, use_symbol_access: true)

alternatives
Wrap an object by OpenStruct before giving it to the initializer.

e.g.

UserPbSerializer.new(OpenStruct.new({
  id: 1234,
  name: `John Smith`,
}))

I'm using this solution temporarily, but it's a little complicated :(

@NotFounds NotFounds added the enhancement New feature or request label Dec 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant