Skip to content

Commit 3c85321

Browse files
authored
Added docs for Deprecator in CONTRIBUTING.md (#2919)
* Added docs for deprecator in CONTRIBUTING.md * Updated CONTRIBUTING.md with test instructions for deprecated Generators
1 parent 5b27fe4 commit 3c85321

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

CONTRIBUTING.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,38 @@ module Faker
158158
end
159159
```
160160

161+
## Deprecating Generators
162+
163+
To deprecate entire generators and provide backwards compatibility when it's possible, use this custom [Faker::Deprecator](https://github.com/faker-ruby/faker/blob/main/lib/helpers/deprecator.rb) helper module.
164+
It's useful for renaming a generator, for example, renaming `IDNumber` to `IdNumber`. Here's how to use it:
165+
166+
- include the `Faker::Deprecator` module after the class definition.
167+
- add the `deprecate_generator` method with the old and new class names as arguments.
168+
169+
```rb
170+
module Faker
171+
class IdNumber < Base
172+
## methods
173+
end
174+
175+
include Faker::Deprecator
176+
deprecate_generator('IDNumber', IdNumber)
177+
end
178+
```
179+
180+
`Faker::IDNumber` is now deprecated. Despite the deprecation, it will still be available with logged warnings and will be removed in the next major release.
181+
182+
```rb
183+
Faker::IDNumber.valid #=> "552-56-3593"
184+
185+
## Deprecation warning
186+
DEPRECATION WARNING: Faker::IDNumber is deprecated. Use Faker::IdNumber instead.
187+
```
188+
189+
We recommend adding tests for both the deprecated and new generators to ensure that the deprecation process is working as expected.
190+
Check out this [PR](https://github.com/faker-ruby/faker/pull/2856) for reference.
191+
192+
161193
## YAML files
162194

163195
Please use dash syntax for YAML arrays. The dash syntax facilitates code reviews by making it easier to see what items were added or removed from the lists.

0 commit comments

Comments
 (0)