Module: Knuckles::Stages::Hydrator
Overview
The hydrator converts minimal objects in a prepared collection into fully “hydrated” versions of the same record. For example, the initial ‘model` may only have the `id` and `updated_at` timestamp selected, which is ideal for fetching from the cache. If the object wasn’t in the cache then all of the fields are needed for a complete rendering, so the hydration call will use the passed relation to fetch the full model and any associations.
This is a generic hydrator suitable for any type of collection. If you are working with ‘ActiveRecord` you’ll want to use the ‘Knuckles::Active::Hydrator` module instead.
Instance Method Summary collapse
-
#call(prepared, options) ⇒ Object
Convert all uncached objects into their full representation.
Instance Method Details
#call(prepared, options) ⇒ Object
Convert all uncached objects into their full representation.
32 33 34 35 36 37 38 39 40 |
# File 'lib/knuckles/stages/hydrator.rb', line 32 def call(prepared, ) hydrate = [:hydrate] if hydrate && any_missing?(prepared) hydrate.call(hydratable(prepared)) end prepared end |