pb-serializer
pb-serializer copied to clipboard
Enable to give a hash object to initializer
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 :(