blueprinter icon indicating copy to clipboard operation
blueprinter copied to clipboard

Unwrap a blueprint into another blueprint

Open Caceresenzo opened this issue 4 years ago • 0 comments

Hi

Is there is a way to unwrap a view into another view?

Here is an exemple:


## These classes

class User
     # has a name
     # has an email
     # has a profile
end

class UserProfile
    # has a win count
    # has a loss count
end

## With these blueprints

class UserBlueprint < Blueprinter::Base
  identifier :id
  fields :name
end

class UserProfileBlueprint < Blueprinter::Base
  fields :win_count, :loss_count
  unwrap :user, blueprint: UserBlueprint 
end

## Can be used to produce:

UserProfileBlueprint.render(an_user_profile)
# => { "id": 1, "name": "John", "win_count": 3, "loss_count": 2 }

Can this be easily be implemented?

I am using Java Jackson's JsonUnwrapped as a reference here, since I can't find an equivalent with this library.

Thanks

EDIT: Wrong calling argument EDIT 2: Fixed typos

Caceresenzo avatar Apr 08 '21 18:04 Caceresenzo