Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7fd8fc6
chore(cnpj-utils): update package metadata
juliolmuller Jul 23, 2026
15d2a86
feat(cnpj-utils): implement unified API for CNPJ handling
juliolmuller Jul 23, 2026
34f2c43
test(cnpj-utils): create test file with comprehensive spec suite
juliolmuller Jul 23, 2026
dda61d2
docs(cnpj-utils): create changelogs file
juliolmuller Jul 23, 2026
789114b
docs(cnpj-utils): create README file
juliolmuller Jul 23, 2026
f110f43
docs(cnpj-utils): create Portuguese version of README file
juliolmuller Jul 23, 2026
b632e19
chore: add guidelines for re-exporting components in aggregator packages
juliolmuller Jul 23, 2026
c4f2122
chore(cnpj-utils): update gemspec to include additional documentation…
juliolmuller Jul 23, 2026
c321b7e
chore(cpf-dv): update gemspec to include additional documentation files
juliolmuller Jul 23, 2026
4be2ac9
chore(cpf-fmt): update gemspec to include additional documentation files
juliolmuller Jul 23, 2026
fb3ce74
chore(cpf-gen): update gemspec to include additional documentation files
juliolmuller Jul 23, 2026
a356a8d
chore(cpf-val): update gemspec to include additional documentation files
juliolmuller Jul 23, 2026
5e4e285
chore(cpf-utils): update gemspec to include additional documentation …
juliolmuller Jul 23, 2026
166bd3a
chore(br-utils): update gemspec to include additional documentation f…
juliolmuller Jul 23, 2026
784a0f2
docs(cnpj-utils): fix link href
juliolmuller Jul 23, 2026
9813225
refactor(cnpj-utils): introduce `TypeMismatchError` for non-Hash sett…
juliolmuller Jul 23, 2026
dfb9b03
docs(cnpj-utils): update error documentation for clarity
juliolmuller Jul 24, 2026
c4e79fa
docs(cnpj-utils): enhance error documentation and clarify rescue beha…
juliolmuller Jul 24, 2026
d05553d
docs(cnpj-dv): standardize code snippets formatting
juliolmuller Jul 24, 2026
66f43b0
docs(cnpj-fmt): standardize code snippets formatting
juliolmuller Jul 24, 2026
6562880
docs(cnpj-gen): standardize code snippets formatting
juliolmuller Jul 24, 2026
6010362
docs(cnpj-val): standardize code snippets formatting
juliolmuller Jul 24, 2026
70ad7e7
docs(cpf-dv): standardize code snippets formatting
juliolmuller Jul 24, 2026
d844492
docs(cpf-fmt): standardize code snippets formatting
juliolmuller Jul 24, 2026
0d5fd96
docs(cpf-gen): standardize code snippets formatting
juliolmuller Jul 24, 2026
0558cc2
docs(cpf-val): standardize code snippets formatting
juliolmuller Jul 24, 2026
8efbd45
refactor(cnpj-utils): improve `nil` checks for settings and options
juliolmuller Jul 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,31 @@ Before finishing any task that adds, changes, or documents errors:
10. A summary table exists with the required columns and ordering, listing only defined failure modes.
11. A rescue-granularity section exists with the four levels above, using real library classes.
12. No docs mention `rescue Exception` or inheriting from `Exception` directly.

---

## Aggregator package re-exports

Applies to aggregator gems such as `*-utilities` and `br-utilities` that load component packages and expose a unified façade.

### Shape

- One re-export file per component under `src/<agg-pkg>/<component_snake>.rb` (e.g. `src/cnpj-utilities/cnpj_fmt.rb`).
- Nest the full sibling module on the façade: `<Utils>::CnpjFmt = ::CnpjFmt` (same-object assignment only — no wrappers).
- Root shortcuts only for the three (or package-appropriate) **main classes** (e.g. `<Utils>::CnpjFormatter = CnpjFmt::CnpjFormatter`).
- Options, helpers, errors, and types stay under the nested module — **not** aliased at the `<Utils>` root.
- Root sibling modules (`CnpjFmt`, `CnpjGen`, `CnpjVal`, …) remain supported unchanged.
- Require the re-export files from the aggregator entrypoint **after** class/module promotion and **after** the façade implementation file.

### Default singleton + class helpers

When the façade mirrors a JS default export / Python module-level singleton:

- Expose a mutable constant `<Utils>::DEFAULT = new` (UPPERCASE names a constant binding, not an immutable value — do not freeze the instance).
- Add class-method aliases for each façade operation that forward to `DEFAULT` (e.g. `CnpjUtils.format` / `.generate` / `.is_valid`). Prefer these in end-user docs as the quick path.
- Mutating `DEFAULT` affects subsequent class-helper calls; `CnpjUtils.new` (custom) instances stay independent.
- Specs: helper existence, parity with `DEFAULT`, mutability coupling with restore, custom-instance independence.

### Reference

Shipped reference: `ruby/packages/cnpj-utilities` (`CnpjUtils::CnpjFmt` nest + `CnpjUtils::CnpjFormatter` shortcut; `DEFAULT` + class helpers).
2 changes: 1 addition & 1 deletion packages/br-utilities/br-utilities.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 3.1'
spec.metadata['source_code_uri'] = spec.homepage
spec.metadata['rubygems_mfa_required'] = 'true'
spec.files = Dir['src/**/*'] + ['LICENSE', 'README.md'].select { |f| File.file?(f) }
spec.files = Dir['src/**/*'] + ['LICENSE', 'README.md', 'README.pt.md', 'CHANGELOG.md']
spec.require_paths = ['src']
spec.add_dependency 'cnpj-utilities', '>= 0'
spec.add_dependency 'cpf-utilities', '>= 0'
Expand Down
22 changes: 11 additions & 11 deletions packages/cnpj-dv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ require 'cnpj-dv'

check_digits = CnpjDV::CnpjCheckDigits.new('914157320007')

check_digits.first # => '9'
check_digits.second # => '3'
check_digits.both # => '93'
check_digits.cnpj # => '91415732000793'
check_digits.first # => '9'
check_digits.second # => '3'
check_digits.both # => '93'
check_digits.cnpj # => '91415732000793'
```

With alphanumeric CNPJ (new format):
Expand All @@ -81,10 +81,10 @@ require 'cnpj-dv'

check_digits = CnpjDV::CnpjCheckDigits.new('MGKGMJ9X0001')

check_digits.first # => '6'
check_digits.second # => '8'
check_digits.both # => '68'
check_digits.cnpj # => 'MGKGMJ9X000168'
check_digits.first # => '6'
check_digits.second # => '8'
check_digits.both # => '68'
check_digits.cnpj # => 'MGKGMJ9X000168'
```


Expand Down Expand Up @@ -178,7 +178,7 @@ rescue CnpjDV::DomainError
- **Example:**

```ruby
CnpjDV::CnpjCheckDigits.new(12_345_678_000_100) # raises CnpjDV::TypeMismatchError
CnpjDV::CnpjCheckDigits.new(12_345_678_000_100) # raises CnpjDV::TypeMismatchError
```

- **How to rescue it:**
Expand All @@ -199,7 +199,7 @@ rescue TypeError
- **Example:**

```ruby
CnpjDV::CnpjCheckDigits.new('12345678901') # raises CnpjDV::InvalidLengthError
CnpjDV::CnpjCheckDigits.new('12345678901') # raises CnpjDV::InvalidLengthError
```

- **How to rescue it:**
Expand All @@ -220,7 +220,7 @@ rescue CnpjDV::DomainError
- **Example:**

```ruby
CnpjDV::CnpjCheckDigits.new('000000000001') # raises CnpjDV::ValidationError
CnpjDV::CnpjCheckDigits.new('000000000001') # raises CnpjDV::ValidationError
```

- **How to rescue it:**
Expand Down
20 changes: 10 additions & 10 deletions packages/cnpj-dv/README.pt.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ require 'cnpj-dv'

check_digits = CnpjDV::CnpjCheckDigits.new('914157320007')

check_digits.first # => '9'
check_digits.second # => '3'
check_digits.both # => '93'
check_digits.cnpj # => '91415732000793'
check_digits.first # => '9'
check_digits.second # => '3'
check_digits.both # => '93'
check_digits.cnpj # => '91415732000793'
```

Com CNPJ alfanumérico (novo formato):
Expand All @@ -58,10 +58,10 @@ require 'cnpj-dv'

check_digits = CnpjDV::CnpjCheckDigits.new('MGKGMJ9X0001')

check_digits.first # => '6'
check_digits.second # => '8'
check_digits.both # => '68'
check_digits.cnpj # => 'MGKGMJ9X000168'
check_digits.first # => '6'
check_digits.second # => '8'
check_digits.both # => '68'
check_digits.cnpj # => 'MGKGMJ9X000168'
```

## Utilização
Expand Down Expand Up @@ -149,7 +149,7 @@ rescue CnpjDV::DomainError
- **Exemplo:**

```ruby
CnpjDV::CnpjCheckDigits.new(12_345_678_000_100) # levanta CnpjDV::TypeMismatchError
CnpjDV::CnpjCheckDigits.new(12_345_678_000_100) # levanta CnpjDV::TypeMismatchError
```

- **Como resgatar:**
Expand All @@ -170,7 +170,7 @@ rescue TypeError
- **Exemplo:**

```ruby
CnpjDV::CnpjCheckDigits.new('12345678901') # levanta CnpjDV::InvalidLengthError
CnpjDV::CnpjCheckDigits.new('12345678901') # levanta CnpjDV::InvalidLengthError
```

- **Como resgatar:**
Expand Down
30 changes: 15 additions & 15 deletions packages/cnpj-fmt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ require 'cnpj-fmt'

cnpj = '03603568000195'

CnpjFmt.cnpj_fmt(cnpj) # => "03.603.568/0001-95"
CnpjFmt.cnpj_fmt(cnpj, hidden: true) # => "03.603.***/****-**"
CnpjFmt.cnpj_fmt( # => "03603568|0001_95"
CnpjFmt.cnpj_fmt(cnpj) # => "03.603.568/0001-95"
CnpjFmt.cnpj_fmt(cnpj, hidden: true) # => "03.603.***/****-**"
CnpjFmt.cnpj_fmt( # => "03603568|0001_95"
cnpj,
dot_key: '',
slash_key: '|',
Expand Down Expand Up @@ -119,15 +119,15 @@ require 'cnpj-fmt'

cnpj = '03603568000195'

CnpjFmt.cnpj_fmt(cnpj) # => "03.603.568/0001-95"
CnpjFmt.cnpj_fmt(cnpj, hidden: true) # masked with defaults
CnpjFmt.cnpj_fmt( # => "03603568|0001_95"
CnpjFmt.cnpj_fmt(cnpj) # => "03.603.568/0001-95"
CnpjFmt.cnpj_fmt(cnpj, hidden: true) # masked with defaults
CnpjFmt.cnpj_fmt( # => "03603568|0001_95"
cnpj,
dot_key: '',
slash_key: '|',
dash_key: '_'
)
CnpjFmt.cnpj_fmt(cnpj, { # Hash form
CnpjFmt.cnpj_fmt(cnpj, { # Hash form
hidden: true,
hidden_key: '#'
})
Expand Down Expand Up @@ -159,9 +159,9 @@ require 'cnpj-fmt'
formatter = CnpjFmt::CnpjFormatter.new(hidden: true)
cnpj = '03603568000195'

formatter.format(cnpj) # uses instance masking
formatter.format(cnpj, hidden: false) # this call only: unmasked
formatter.format(cnpj) # back to instance defaults
formatter.format(cnpj) # uses instance masking
formatter.format(cnpj, hidden: false) # this call only: unmasked
formatter.format(cnpj) # back to instance defaults
```

Alphanumeric input and array input:
Expand Down Expand Up @@ -283,7 +283,7 @@ rescue CnpjFmt::DomainError
- **Example:**

```ruby
CnpjFmt::CnpjFormatter.new.format(12_345) # raises CnpjFmt::TypeMismatchError
CnpjFmt::CnpjFormatter.new.format(12_345) # raises CnpjFmt::TypeMismatchError
```

- **How to rescue it:**
Expand All @@ -307,10 +307,10 @@ rescue TypeError
CnpjFmt::CnpjFormatter.new.format(
'short',
on_fail: ->(_value, error) {
error # => #<CnpjFmt::InvalidLengthError ...> (a DomainError)
error # => #<CnpjFmt::InvalidLengthError ...> (a DomainError)
'invalid'
}
) # => "invalid"
) # => "invalid"

```

Expand Down Expand Up @@ -358,7 +358,7 @@ rescue ArgumentError
- **Example:**

```ruby
CnpjFmt::CnpjFormatterOptions.new(hidden_start: 14) # raises CnpjFmt::OutOfRangeError
CnpjFmt::CnpjFormatterOptions.new(hidden_start: 14) # raises CnpjFmt::OutOfRangeError
```

- **How to rescue it:**
Expand All @@ -379,7 +379,7 @@ rescue CnpjFmt::DomainError
- **Example:**

```ruby
CnpjFmt::CnpjFormatterOptions.new(dot_key: 'å') # raises CnpjFmt::ValidationError
CnpjFmt::CnpjFormatterOptions.new(dot_key: 'å') # raises CnpjFmt::ValidationError
```

- **How to rescue it:**
Expand Down
30 changes: 15 additions & 15 deletions packages/cnpj-fmt/README.pt.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ require 'cnpj-fmt'

cnpj = '03603568000195'

CnpjFmt.cnpj_fmt(cnpj) # => "03.603.568/0001-95"
CnpjFmt.cnpj_fmt(cnpj, hidden: true) # => "03.603.***/****-**"
CnpjFmt.cnpj_fmt( # => "03603568|0001_95"
CnpjFmt.cnpj_fmt(cnpj) # => "03.603.568/0001-95"
CnpjFmt.cnpj_fmt(cnpj, hidden: true) # => "03.603.***/****-**"
CnpjFmt.cnpj_fmt( # => "03603568|0001_95"
cnpj,
dot_key: '',
slash_key: '|',
Expand Down Expand Up @@ -106,15 +106,15 @@ require 'cnpj-fmt'

cnpj = '03603568000195'

CnpjFmt.cnpj_fmt(cnpj) # => "03.603.568/0001-95"
CnpjFmt.cnpj_fmt(cnpj) # => "03.603.568/0001-95"
CnpjFmt.cnpj_fmt(cnpj, hidden: true) # mascarado com padrões
CnpjFmt.cnpj_fmt( # => "03603568|0001_95"
CnpjFmt.cnpj_fmt( # => "03603568|0001_95"
cnpj,
dot_key: '',
slash_key: '|',
dash_key: '_'
)
CnpjFmt.cnpj_fmt(cnpj, { # forma com Hash
CnpjFmt.cnpj_fmt(cnpj, { # forma com Hash
hidden: true,
hidden_key: '#'
})
Expand Down Expand Up @@ -146,9 +146,9 @@ require 'cnpj-fmt'
formatter = CnpjFmt::CnpjFormatter.new(hidden: true)
cnpj = '03603568000195'

formatter.format(cnpj) # usa mascaramento da instância
formatter.format(cnpj, hidden: false) # só nesta chamada: sem máscara
formatter.format(cnpj) # volta aos padrões da instância
formatter.format(cnpj) # usa mascaramento da instância
formatter.format(cnpj, hidden: false) # só nesta chamada: sem máscara
formatter.format(cnpj) # volta aos padrões da instância
```

Entrada alfanumérica e array:
Expand All @@ -159,7 +159,7 @@ require 'cnpj-fmt'
formatter = CnpjFmt::CnpjFormatter.new

formatter.format('RK0CMT3W000100') # => "RK.0CM.T3W/0001-00"
formatter.format([ # => "RK.0CM.T3W/0001-00"
formatter.format([ # => "RK.0CM.T3W/0001-00"
'RK',
'0CM',
'T3W',
Expand Down Expand Up @@ -270,7 +270,7 @@ rescue CnpjFmt::DomainError
- **Exemplo:**

```ruby
CnpjFmt::CnpjFormatter.new.format(12_345) # levanta CnpjFmt::TypeMismatchError
CnpjFmt::CnpjFormatter.new.format(12_345) # levanta CnpjFmt::TypeMismatchError
```

- **Como resgatar:**
Expand All @@ -294,10 +294,10 @@ rescue TypeError
CnpjFmt::CnpjFormatter.new.format(
'short',
on_fail: ->(_value, error) {
error # => #<CnpjFmt::InvalidLengthError ...> (um DomainError)
error # => #<CnpjFmt::InvalidLengthError ...> (um DomainError)
'invalid'
}
) # => "invalid"
) # => "invalid"
```

- **Como resgatar:** Trate dentro do `on_fail` (caso típico), ou resgate se você o reerguer:
Expand Down Expand Up @@ -344,7 +344,7 @@ rescue ArgumentError
- **Exemplo:**

```ruby
CnpjFmt::CnpjFormatterOptions.new(hidden_start: 14) # levanta CnpjFmt::OutOfRangeError
CnpjFmt::CnpjFormatterOptions.new(hidden_start: 14) # levanta CnpjFmt::OutOfRangeError
```

- **Como resgatar:**
Expand All @@ -365,7 +365,7 @@ rescue CnpjFmt::DomainError
- **Exemplo:**

```ruby
CnpjFmt::CnpjFormatterOptions.new(dot_key: 'å') # levanta CnpjFmt::ValidationError
CnpjFmt::CnpjFormatterOptions.new(dot_key: 'å') # levanta CnpjFmt::ValidationError
```

- **Como resgatar:**
Expand Down
Loading