Replace Decorator with PartBuilder, supporting built-in part class resolution from a namespace #80
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Now, a view controller can be configured with a
part_namespace
and the default part builder will look up part classes to use from that namespace.For example:
This works for decorated attributes, too. If the part classes looked like this:
Then
locals[:user].profile
would be aMyParts::Profile
.Providing aliases for part names continues to work largely as before, e.g.
expose :user, as: :admin_user
will return the part as aMyParts::AdminUser
(if it exists).The API for providing a the part to use for array values has changed, however. Previously it took the form of
as: {:collection_part_name => :item_part_name}
. However, this made things feel pretty awkward if you didn't want to supply a custom name for the individual item (as: {:collection_part_name => nil}
is pretty bad). Now you can provide one or both name aliases via an array syntax, e.g.as: [:collection_part_name]
if you only want to provide an alias for the collection, oras: [:collection_part_name, :item_part_name]
if you want to provide both. The array format here also works nicely as a mnemonic device, since it's relating to the wrapping of an array value.Names are resolved using an inflector (by default a
Dry::Inflector
instance) which can be configured on view controllers via aninflector
setting.Custom part builders can still be provided to view controllers via a
part_builder
setting. When the view controller is initialized, the part builder will be prepared with the part namespace and inflector like so:So any custom part builder will need to conform to this interface.
Replacing the
decorator
name withpart_builder
not only makes the purpose of the object clearer, but it also paves the way for a relatedscope_builder
to be established as part of an upcoming feature.Resolves #54, resolves #73