procore-oss / blueprinter

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

Extract Rendering Logic from `BaseHelpers` #432

Open lessthanjacob opened 2 months ago

lessthanjacob commented 2 months ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe

No

Describe the feature you'd like to see implemented

Currently, rendering logic is split between a BaseHelpers module (primarily), and Blueprinter::Base (with the former also being included in the latter). I believe this was done to help "slim down" Blueprinter::Base, but BaseHelpers has seemingly turned into a sort of "junk drawer" of methods.

Since rendering is a clearly defined concept in the context of Blueprint, it would be helpful to encapsulate relevant logic in a specific class (e.g. Renderer), which would help with comprehensibility, testability, and extensibility moving forward.

Describe alternatives you've considered

No response

Additional context

At the moment, the rendering flow looks something like so:

sequenceDiagram
actor User as User
participant B as Blueprinter
participant BH as BaseHelper
participant E as Blueprinter.configuration.extensions

User ->> B: .render(Object)
B ->> BH: .prepare_for_render
BH ->> BH: .validate_root_and_meta
BH ->> B: .prepare
B ->> E: .pre_render
E ->> B: Object
B ->> BH: .prepare_data
BH ->> B: Hash | Array
B ->> BH: .prepend_root_and_meta
BH ->> B: Hash | Array
B ->> B: .jsonify
B ->> User: JSON Object
github-actions[bot] commented 3 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.