blueprinter
blueprinter copied to clipboard
Extract Rendering Logic from `BaseHelpers`
Is there an existing issue for this?
- [X] I have searched the existing issues
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