Skip to content

Additional APIs #30

@kortirso

Description

@kortirso

While we were integrating props into our application, we added some additional APIs that were spied on by the Jbuilder.

  1. json.optional! - defines attribute or structure and marks it as optional, during serialization this method checks condition and renders or does not render such attribute

example of usage

json.optional! :properties do
  json.optional! :value, -> { object.value } # lambda here is to avoid value calculations before checking conditions for rendering
end
  1. json.extract! - extracts the mentioned attributes or hash elements from the passed object and turns them into attributes of the JSON

example of usage - json.extract! object, :id, :unit

instead of

json.id object.id
json.unit object.unit
  1. json.partial! - renders partial without setting result to some key

@jho406 do you have any plans to integrate such features to PropsTemplate? Or maybe I can share their implementation and then dicsuss/modify/accept/reject them, what do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions