procore-oss / blueprinter

Simple, Fast, and Declarative Serialization Library for Ruby
MIT License
1.14k stars 109 forks source link

How to create a field that is derived from other fields that are defined in the blueprint? #394

Closed sagexfors closed 9 months ago

sagexfors commented 9 months ago

Suppose I have a Person model that has first, middle, and last name.

then i create a new field

:field full_name do |person, options|
  # concatenate the names
end

how to use the full_name field here?

:field full_name_and_id do |person, options|
  # full_name field that i defined above + id
  # person.full_name returns nomethod error
end
sqlninja commented 9 months ago

Any reason not to define the full_name method in your Person model? Then it would be accessible in your full_name_and_id field and could just defined as a regular field above...