Improve collection ergonomics and add Base#empty? default semantics - #2
Open
mjgiarlo wants to merge 1 commit into
Open
Improve collection ergonomics and add Base#empty? default semantics#2mjgiarlo wants to merge 1 commit into
mjgiarlo wants to merge 1 commit into
Conversation
This PR improves day-to-day form-object ergonomics by expanding collection behavior on `Blanks::AssociationProxy` and adding default `empty?` semantics to `Blanks::Base`.
- Kept association emptiness behavior (`AssociationProxy#empty?`) as a direct core API and documented adjacent collection ergonomics.
- Updated `AssociationProxy#any?` to support both no-block and block forms.
- Added `AssociationProxy#reverse` to return records in reverse order.
- Added `Base#empty?` with default semantics: all attribute values are blank.
- Added spec coverage for the above changes.
- Updated README with collection proxy and `empty?` usage notes.
- Added CHANGELOG entries under Unreleased.
Apps using Blanks often treat `has_many` associations as collections. Without block-aware `any?` and `reverse`, callers must unwrap via `to_a` for routine operations.
Likewise, many applications define identical `empty?` methods in local base forms. Moving this to `Blanks::Base` provides a shared default and reduces boilerplate.
- `AssociationProxy#any?`:
- `proxy.any?` works as before.
- `proxy.any? { |item| ... }` now evaluates the block against members.
- `AssociationProxy#reverse`:
- Returns an array in reverse order.
- Does not mutate the proxy's underlying order.
- `Base#empty?`:
- Returns true when all `attributes` values are blank.
- Returns false when any attribute is present.
- Subclasses may still override for custom emptiness semantics.
- Backward compatible for existing `any?` calls without a block.
- `to_a` remains available and unchanged.
- Adding `Base#empty?` may affect classes that relied on `NoMethodError`, but aligns with common form-object expectations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR improves day-to-day form-object ergonomics by expanding collection behavior on
Blanks::AssociationProxyand adding defaultempty?semantics toBlanks::Base.AssociationProxy#empty?) as a direct core API and documented adjacent collection ergonomics.AssociationProxy#any?to support both no-block and block forms.AssociationProxy#reverseto return records in reverse order.Base#empty?with default semantics: all attribute values are blank.empty?usage notes.Apps using Blanks often treat
has_manyassociations as collections. Without block-awareany?andreverse, callers must unwrap viato_afor routine operations.Likewise, many applications define identical
empty?methods in local base forms. Moving this toBlanks::Baseprovides a shared default and reduces boilerplate.AssociationProxy#any?:proxy.any?works as before.proxy.any? { |item| ... }now evaluates the block against members.AssociationProxy#reverse:Base#empty?:attributesvalues are blank.Backward compatible for existing
any?calls without a block.to_aremains available and unchanged.Adding
Base#empty?may affect classes that relied onNoMethodError, but aligns with common form-object expectations.