-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor
Faker::IDNumber
to Faker::IdNumber
to be more consistent…
… with other generator's naming convention. (#2858) * Deprecate IDNumber to IdNumber per issue#2787 * wip * Add a Faker::Deprecator module Co-authored-by: Thiago Araujo <[email protected]> * Add more specs and improve warning message --------- Co-authored-by: jamal.mohamed <[email protected]> Co-authored-by: Stefanni Brasil <[email protected]> Co-authored-by: Thiago Araujo <[email protected]>
- Loading branch information
1 parent
3f7371e
commit f586da7
Showing
13 changed files
with
464 additions
and
79 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,52 @@ | ||
# Faker::IDNumber | ||
# Faker::IdNumber | ||
|
||
```ruby | ||
# Generate a valid US Social Security number | ||
Faker::IDNumber.valid #=> "552-56-3593" | ||
Faker::IdNumber.valid #=> "552-56-3593" | ||
|
||
# Generate an invalid US Social Security number | ||
Faker::IDNumber.invalid #=> "311-72-0000" | ||
Faker::IdNumber.invalid #=> "311-72-0000" | ||
|
||
# Generate a Spanish citizen identifier (DNI) | ||
Faker::IDNumber.spanish_citizen_number #=> "53290236-H" | ||
Faker::IdNumber.spanish_citizen_number #=> "53290236-H" | ||
|
||
# Generate a Spanish foreign born citizen identifier (NIE) | ||
Faker::IDNumber.spanish_foreign_citizen_number #=> "Z-1600870-Y" | ||
Faker::IdNumber.spanish_foreign_citizen_number #=> "Z-1600870-Y" | ||
|
||
# Generate a valid South African ID Number | ||
Faker::IDNumber.south_african_id_number #=> "8105128870184" | ||
Faker::IdNumber.south_african_id_number #=> "8105128870184" | ||
# or | ||
Faker::IDNumber.valid_south_african_id_number #=> "8105128870184" | ||
Faker::IdNumber.valid_south_african_id_number #=> "8105128870184" | ||
|
||
# Generate an invalid South African ID Number | ||
Faker::IDNumber.invalid_south_african_id_number #=> "1642972065088" | ||
Faker::IdNumber.invalid_south_african_id_number #=> "1642972065088" | ||
|
||
# Generate a Brazilian citizen number (CPF) | ||
# Keyword arguments: formatted | ||
Faker::IDNumber.brazilian_citizen_number #=> "53540542221" | ||
Faker::IDNumber.brazilian_citizen_number(formatted: true) #=> "535.405.422-21" | ||
Faker::IdNumber.brazilian_citizen_number #=> "53540542221" | ||
Faker::IdNumber.brazilian_citizen_number(formatted: true) #=> "535.405.422-21" | ||
|
||
# Generate a Brazilian ID Number (RG) | ||
# Keyword arguments: formatted | ||
Faker::IDNumber.brazilian_id #=> "493054029" | ||
Faker::IDNumber.brazilian_id(formatted: true) #=> "49.305.402-9" | ||
Faker::IdNumber.brazilian_id #=> "493054029" | ||
Faker::IdNumber.brazilian_id(formatted: true) #=> "49.305.402-9" | ||
|
||
# Generate a Chilean ID (Rut with 8 digits) | ||
# For more advanced cases, please refer to Faker::ChileRut | ||
Faker::IDNumber.chilean_id #=> "15620613-K" | ||
Faker::IdNumber.chilean_id #=> "15620613-K" | ||
|
||
# Generate a Croatian ID number (OIB) | ||
# Keyword arguments: international | ||
Faker::IDNumber.croatian_id #=> "88467617508" | ||
Faker::IDNumber.croatian_id(international: true) #=> "HR88467617508" | ||
Faker::IdNumber.croatian_id #=> "88467617508" | ||
Faker::IdNumber.croatian_id(international: true) #=> "HR88467617508" | ||
|
||
# Generate a Danish ID number (CPR) | ||
# Keyword arguments: formatted, gender, birthday | ||
Faker::IDNumber.danish_id_number #=> "050390-9980" | ||
Faker::IDNumber.danish_id_number(formatted: true) #=> "050390-9980" | ||
Faker::IDNumber.danish_id_number(birthday: Date.new(1990, 3, 5)) #=> "050390-9980" | ||
Faker::IDNumber.danish_id_number(gender: :female) #=> "050390-9980" | ||
Faker::IdNumber.danish_id_number #=> "050390-9980" | ||
Faker::IdNumber.danish_id_number(formatted: true) #=> "050390-9980" | ||
Faker::IdNumber.danish_id_number(birthday: Date.new(1990, 3, 5)) #=> "050390-9980" | ||
Faker::IdNumber.danish_id_number(gender: :female) #=> "050390-9980" | ||
|
||
# Generate a valid French Social Security number (INSEE number) | ||
Faker::IDNumber.french_insee_number #=> "22510589696868" | ||
Faker::IdNumber.french_insee_number #=> "22510589696868" | ||
``` |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
# Based on Rails ActiveSupport Deprecator | ||
# https://github.com/rails/rails/blob/6f0d1ad14b92b9f5906e44740fce8b4f1c7075dc/activesupport/lib/active_support/deprecation/constant_accessor.rb | ||
|
||
# rubocop:disable Style/ClassVars | ||
module Faker | ||
module Deprecator | ||
def self.included(base) | ||
extension = Module.new do | ||
def const_missing(missing_const_name) | ||
if class_variable_defined?(:@@_deprecated_constants) && (replacement = class_variable_get(:@@_deprecated_constants)[missing_const_name.to_s]) | ||
$stdout.puts("DEPRECATION WARNING: #{name}::#{replacement[:old_generator]} is deprecated. Use #{replacement[:new_constant]} instead.") | ||
return replacement[:new_constant] | ||
end | ||
|
||
super | ||
end | ||
|
||
def deprecate_generator(old_generator_name, new_generator_constant) | ||
class_variable_set(:@@_deprecated_constants, {}) unless class_variable_defined?(:@@_deprecated_constants) | ||
class_variable_get(:@@_deprecated_constants)[old_generator_name] = { new_constant: new_generator_constant, old_generator: old_generator_name } | ||
end | ||
end | ||
|
||
base.singleton_class.prepend extension | ||
end | ||
end | ||
end | ||
# rubocop:enable Style/ClassVars |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
en: | ||
faker: | ||
id_number: | ||
valid: "#{IDNumber.ssn_valid}" | ||
valid: "#{IdNumber.ssn_valid}" | ||
invalid: ['000-##-####', '###-00-####', '###-##-0000', '666-##-####', '9##-##-####'] |
Oops, something went wrong.