You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -158,6 +158,38 @@ module Faker
158
158
end
159
159
```
160
160
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
+
moduleFaker
171
+
classIdNumber < Base
172
+
## methods
173
+
end
174
+
175
+
includeFaker::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
+
DEPRECATIONWARNING:Faker::IDNumber is deprecated. UseFaker::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
+
161
193
## YAML files
162
194
163
195
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