- Upgrade to latest Attributor gem (which has JSON-schema support), and add json-schema methods for blueprints.
- Include Attributor::Dumpable in Blueprint, so it renders (semi) correctly if
rendered with just
true
specified for fields. - Fix bug rendering subobjects with nil values (manifested when
include_nil: true
there’s an explicit subsection of fields)
- Ensure we call
object.dump
in Renderer when fully dumping an instance (or array of instances) that have the Attributor::Dumpable module (i.e., when no subfields were selected)- In other words, attributor types (custom or not) will need to include the Attributor::Dumpable module and properly implement the dump instance method to produce the right output with native ruby objects.
- Ensure
Blueprint
validates advanced requirements.
- Reworked FieldExpander's behavior with circular references.
- Removed
Praxis::FieldExpander::CircularExpansionError
FieldExpander#expand
now returns self-referential hashes for circular expansions
- Removed
Renderer#render
catches stack overflows and returns aPraxis::Rendering::CircularRenderingError
, which includes a portions from the start and end of the context at the time of the exception.- Report
anonymous
in Blueprints followingAttributor
semantics.
- Added
FieldExpander
, a new class that recursively expands a tree of of attributes for Blueprint types as well as view objects into their lowest-level values.- For example, for the
Person
andAddress
blueprints defined in spec_blueprints.rb:FieldExpander.expand(Person, {name: true, full_name: true})
would return{name: true, full_name: {first: true, last:true}}
.
- Attempting to expand attributes with circular references (i.e. the
a person's address, where that address then references that person) will
raise a
Praxis::FieldExpander::CircularExpansionError
error.
- For example, for the
- Added
Renderer
, a new class for rendering objects (typically Blueprint instances) with an explicit and recursive set of fields (as fromFieldexpander
).- For example:
render(person, name: true)
would produce{name: person.name}
render(person, name: true, address: {state: true})
would produce{name: person.name, address: {state: person.address.state}}
- Accepts an
include_nil:
option when initialized, that if true will cause the renderer to output values that are nil, rather than omit them. Note: this will apply to the entire rendering, there is no way to set it for only a portion of the rendering, or on a per-View basis.
- For example:
- Added
Blueprint.domain_model
to specify the underlying domain model, e.g. aPraxis::Mapper::Resource
. Accepts a string value that is resolved whenBlueprint.finalize!
is called. Defaults toObject
. Blueprint.load
will use thedomain_model
to wrap the incoming object if it is not an instance of that class. Note: this does not change existing default ifdomain_model
is not set.- Refactored
View
andCollectionView
rendering to use aRenderer
with a set of expanded fields. - The automatically generated
:master
view will now render sub-attributes using their:default
view, rather than:master
. Blueprint#render
now usesRenderer
andFieldExpander
internally. In most cases this will continue to function identically to the old behavior, but- Views defined with
Blueprint.view
, including subviews defined inside, no longer accept the:include_nil
option. This can be set using the same option onRenderer
described above.
- Added instrumentation through
ActiveSupport::Notifications
- Use the 'praxis.blueprint.render to subscribe to
Blueprint#render
calls
- Use the 'praxis.blueprint.render to subscribe to
- Fixed handling of objects passed in to
Blueprint.example
. - Bumped attributor dependnecy to >= 4.0.1
- relaxed attributor dependency to >= 3.0
- Fix
Blueprint.new
handling of caching when the wrapped object responds toidentity_map
, but does not have one set. - Undefine JRuby package helper methods in
Model
(org, java...) - Added support for rendering custom views
- Internally, a
View
object can now be dumped passing a:fields
option (which is a hash, that can recursively will define which sub-attributes to render along the way). See this spec for an example. Blueprints
will also accept the:fields
option (with the same hash syntax), but it will also accept an array to imply the list of top-level attributes to render (when recursion is not necessary)- Caching of rendered blueprints will continue to work if the view is re-rendered with equivalent
:fields
- Internally, a
- Deprecate `Blueprint.render(view_name,...) positional param
- Please use :view named parameter instead. I.e.,
render(:default, context: ...)
=>render(view: :default, context: ...)
- Please use :view named parameter instead. I.e.,
- Improve error for nonexistent view attributes in media type
- Added
family
method to Blueprints to follow the newAttributor
practices.
- Added
include_nil
option toView
for refining the rendering of nil values.- This can be set when defining the view with
Blueprint.view
, and defaults to false. For example:view :default, include_nil: true { ... }
.
- This can be set when defining the view with
- Fixed
Blueprint.describe
to output the proper:id
. That is: the 'id` from the Class name, rather than the internal Struct attribute. - Fixed
Blueprint.dump(nil)
raising aNoMethodError
- Fixed
Blueprint.load(nil)
to properly support therecurse
option.
Blueprint
readers now alwaysload
the value for an attribute before returning it.
- Added CollectionView, a special type of view that renders an array of objects with another view.
- Relaxed ActiveSupport version dependency (from 4 to >=3)
Initial release!