Skip to content

Enable to give a hash object to initializer #51

@NotFounds

Description

@NotFounds

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 :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions