[cpf-utils] Create package to consolidate itilities for CPF - #27
Conversation
Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
- Implemented a new `CpfUtils` class that consolidates formatting, generation, and validation functionalities for CPF. - Added nested modules for `CpfFmt`, `CpfGen`, and `CpfVal` to maintain compatibility with existing structures. - Introduced error handling with custom error classes for type mismatches and invalid argument combinations. - Enhanced documentation for public API methods and usage examples. Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
- Removed outdated `cpf_utilities.spec.rb` file. - Added a new `cpf_utils.spec.rb` file containing a complete RSpec test suite for the `CpfUtils` class. - The new tests cover various functionalities including formatting, generation, and validation, ensuring robust behavior across different contexts and options. Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
📝 WalkthroughWalkthroughChangesThe PR replaces the placeholder CPF utilities facade
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 10
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/cpf-utilities/README.md`:
- Around line 329-360: Replace the commented CpfUtils::DomainError/NameError
examples in packages/cpf-utilities/README.md lines 329-360 with a standalone
rescue example using an actual bundled package DomainError or leaf error. Add
the equivalent Portuguese example in packages/cpf-utilities/README.pt.md lines
314-344, keeping both examples consistent with the real component error API and
existing rescue-granularity guidance.
- Around line 385-391: The propagated-error references are incomplete in both
documentation files. Update packages/cpf-utilities/README.md lines 385-391 and
packages/cpf-utilities/README.pt.md lines 370-376 to document every propagated
leaf and callback-delivered error with its inheritance, category, trigger,
example, and rescue guidance; provide equivalent Portuguese content in the
latter file while preserving the existing Validation false-return and formatting
on_fail behavior.
- Around line 261-266: Align both error tables with the API contract: in
packages/cpf-utilities/README.md lines 261-266 and
packages/cpf-utilities/README.pt.md lines 248-251, alphabetize the misuse
entries and distinguish constructor Hash settings from per-call option
instances; in packages/cpf-utilities/README.md lines 304-308 and
packages/cpf-utilities/README.pt.md lines 289-293, correct the
InvalidArgumentCombinationError trigger description to reflect the actual
combination of settings/options and keyword arguments.
In `@packages/cpf-utilities/src/cpf-utilities.rb`:
- Around line 23-28: Declare CpfUtils as a class in version.rb, keeping VERSION
defined on that class, so it can be safely reopened regardless of require order.
Remove the CpfUtils module-to-class promotion logic from cpf-utilities.rb,
including the VERSION capture and remove_const flow.
In `@packages/cpf-utilities/src/cpf-utilities/cpf_utils.rb`:
- Around line 344-348: Update the documentation for the mutable
CpfUtils::DEFAULT singleton to state that its configuration is process-wide and
shared across threads, so mutations can affect concurrent callers. Advise
threaded or isolated work to use CpfUtils.new or per-call options instead.
- Around line 338-342: Update the RuboCop directives surrounding the is_valid
method to use the pinned version’s supported Naming/PredicateName cop instead of
Naming/PredicatePrefix, preserving suppression of the public API’s predicate
naming offense.
- Around line 102-114: Reject unrecognized keywords instead of silently
discarding them in both formatting and constructor settings flows. Add an
ensure_known_keywords! validation call in resolve_settings using SETTINGS_KEYS,
and update the compact_keyword_overrides/Helpers.compact_settings paths as
needed so unknown keys such as hiden or formater raise at the call site while
recognized options retain their current behavior.
- Around line 75-100: Update resolve_formatter, resolve_generator, and
resolve_validator so their duck-typed fallback returns the injected object only
when it responds to the delegated method: format, generate, or is_valid
respectively. Otherwise raise the existing TypeMismatchError used by CpfUtils,
while preserving the nil, concrete-class, and supported-options handling.
In `@packages/cpf-utilities/tests/cpf_utils.spec.rb`:
- Around line 1251-1301: Add smoke examples in the `describe 'package smoke'`
block that verify `described_class` is a `Class`, can be instantiated with
`described_class.new`, and retains a string `VERSION` matching semantic-version
digits. Use aggregate failures for the class and instantiation assertions, and
leave the existing formatting, generation, and validation coverage unchanged.
- Around line 245-247: Update the CpfValidatorOptions assertion in the “does not
expose CpfValidatorOptions” example to call const_defined? with ancestor lookup
disabled, so it checks only constants defined directly on CpfUtils and remains
unaffected by top-level constants.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: ecf03c24-d134-461b-a7b2-7eceecc0d8d1
📒 Files selected for processing (15)
packages/br-utilities/Gemfilepackages/cpf-utilities/CHANGELOG.mdpackages/cpf-utilities/Gemfilepackages/cpf-utilities/README.mdpackages/cpf-utilities/README.pt.mdpackages/cpf-utilities/cpf-utilities.gemspecpackages/cpf-utilities/src/cpf-utilities.rbpackages/cpf-utilities/src/cpf-utilities/cpf_fmt.rbpackages/cpf-utilities/src/cpf-utilities/cpf_gen.rbpackages/cpf-utilities/src/cpf-utilities/cpf_utils.rbpackages/cpf-utilities/src/cpf-utilities/cpf_val.rbpackages/cpf-utilities/src/cpf-utilities/errors.rbpackages/cpf-utilities/src/cpf-utilities/version.rbpackages/cpf-utilities/tests/cpf_utilities.spec.rbpackages/cpf-utilities/tests/cpf_utils.spec.rb
💤 Files with no reviewable changes (3)
- packages/cpf-utilities/tests/cpf_utilities.spec.rb
- packages/cpf-utilities/Gemfile
- packages/br-utilities/Gemfile
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Fix as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/cpf-utilities/README.md`:
- Around line 392-402: The propagated-error summary tables in
packages/cpf-utilities/README.md lines 392-402 and
packages/cpf-utilities/README.pt.md lines 377-387 must use identical ordering:
place every API-misuse error before every domain error, sorting entries
alphabetically by error name within each category; update both tables
consistently.
- Around line 404-420: The propagated error inheritance chains in
packages/cpf-utilities/README.md lines 404-420 and
packages/cpf-utilities/README.pt.md lines 389-404 are incomplete. Update both
references for CpfFmt::DomainError and CpfFmt::TypeMismatchError to include the
native StandardError link while retaining each package Error marker and the
existing inheritance relationships.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 5b7ad473-5043-438d-8742-1aaaeaaa1b3d
📒 Files selected for processing (5)
packages/cpf-utilities/CHANGELOG.mdpackages/cpf-utilities/README.mdpackages/cpf-utilities/README.pt.mdpackages/cpf-utilities/src/cpf-utilities.rbpackages/cpf-utilities/src/cpf-utilities/version.rb
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/cpf-utilities/README.md`:
- Around line 399-401: Complete the inheritance and marker documentation for
every domain-error leaf in packages/cpf-utilities/README.md lines 399-401 and
packages/cpf-utilities/README.pt.md lines 384-386. Update each English and
Portuguese table entry to show the full chain from the leaf through its package
DomainError to RangeError and StandardError, and include the corresponding
package marker (CpfFmt::Error or CpfGen::Error).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 15e8ca47-a3fd-4a8f-95fc-32b96d8b6e10
📒 Files selected for processing (10)
packages/cnpj-utilities/CHANGELOG.mdpackages/cnpj-utilities/README.mdpackages/cnpj-utilities/README.pt.mdpackages/cnpj-utilities/src/cnpj-utilities/cnpj_utils.rbpackages/cnpj-utilities/tests/cnpj_utils.spec.rbpackages/cpf-utilities/CHANGELOG.mdpackages/cpf-utilities/README.mdpackages/cpf-utilities/README.pt.mdpackages/cpf-utilities/src/cpf-utilities/cpf_utils.rbpackages/cpf-utilities/tests/cpf_utils.spec.rb
…heritance Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/cpf-utilities/README.md (1)
404-415: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick winissue (blocking): Complete the required examples for public
DomainErrorancestors.
packages/cpf-utilities/README.md#L404-L415,529-L540: Add concrete formatter and generator calls that raise descendant errors.packages/cpf-utilities/README.pt.md#L389-L400,514-L525: Add the equivalent Portuguese examples.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/cpf-utilities/README.md` around lines 404 - 415, Complete the public DomainError ancestor examples by adding concrete formatter and generator calls that raise descendant errors in packages/cpf-utilities/README.md ranges 404-415 and 529-540, and add equivalent Portuguese examples in packages/cpf-utilities/README.pt.md ranges 389-400 and 514-525. Use the documented descendant types, including OutOfRangeError, ValidationError, and InvalidLengthError where applicable.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@packages/cpf-utilities/README.md`:
- Around line 404-415: Complete the public DomainError ancestor examples by
adding concrete formatter and generator calls that raise descendant errors in
packages/cpf-utilities/README.md ranges 404-415 and 529-540, and add equivalent
Portuguese examples in packages/cpf-utilities/README.pt.md ranges 389-400 and
514-525. Use the documented descendant types, including OutOfRangeError,
ValidationError, and InvalidLengthError where applicable.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: bc8a1628-8196-4920-a5ed-72cbf329fffe
📒 Files selected for processing (3)
packages/cpf-utilities/CHANGELOG.mdpackages/cpf-utilities/README.mdpackages/cpf-utilities/README.pt.md
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Fix as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
…heritance Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Adjustment as per @coderabbitai review comment at #27 (comment). Co-authored-by: CodeRabbit AI <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor Grok 4.5 <cursoragent@cursor.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Resolves #11
Summary by CodeRabbit
CpfUtils) to format, generate, and validate CPFs via a shared default instance.CpfUtils, including usage and error handling; added a 1.0.0 “stable release” changelog entry.CnpjUtils::DEFAULTas a mutable, process-wide singleton and updated related documentation wording.CpfUtilsand removed the old placeholder coverage.