Module: FakePipe::Mutator
- Defined in:
- lib/fake_pipe/mutator.rb
Overview
This class handles mapping between a configured mutation such as ‘phone_number’ and the logic to change the data.
To create a new mutable named configuration create a method prefixed with ‘mutate_`. The method will receive the original cell value and is expected to return the mutated value. Please add comment to the mutate method. The comment is used by `rake methods` to get a listing of all possible mutations.
Constant Summary collapse
- ALPHABET =
('A'..'Z').to_a
- DIGITS =
('0'..'9').to_a
Class Method Summary collapse
- .list ⇒ Object
-
.list_with_comments ⇒ Object
Utility method for outputting available mutators.
- .mutate(name, cell) ⇒ Object
-
.mutate_address_city(_) ⇒ Object
Faker::Address.city.
-
.mutate_address_country(_) ⇒ Object
Faker::Address.country.
-
.mutate_address_line_1(_) ⇒ Object
Faker::Address.street_address.
-
.mutate_address_line_2(_) ⇒ Object
Faker::Address.secondary_address.
-
.mutate_address_postcode(_) ⇒ Object
Faker::Address.postcode.
-
.mutate_address_state(_) ⇒ Object
Faker::Address.state.
-
.mutate_bank_name(_) ⇒ Object
Faker::Bank.name.
-
.mutate_bcrypt_password(_) ⇒ Object
bcrypt password as ‘password’.
-
.mutate_bcrypt_salt(_) ⇒ Object
bcrypt salt used to generate password.
-
.mutate_clean_phone_number(_) ⇒ Object
Faker::PhoneNumber 10-digits only.
-
.mutate_company_catch_phrase(_) ⇒ Object
Faker::Company.catch_phrase.
-
.mutate_company_name(_) ⇒ Object
Faker::Company.name.
-
.mutate_email(_) ⇒ Object
Faker email.
-
.mutate_empty_bracket(_) ⇒ Object
an empty bracket ‘[]’ - good for json::array objects.
-
.mutate_empty_curly(_) ⇒ Object
an empty curly brace ‘{}’ - good for json object and array fields.
-
.mutate_empty_string(_) ⇒ Object
an empty String.
-
.mutate_first_name(_) ⇒ Object
Faker::Name.first_name.
-
.mutate_full_name(_) ⇒ Object
Faker::Name.full_name.
-
.mutate_last_name(_) ⇒ Object
Faker::Name.last_name.
-
.mutate_latitude(_) ⇒ Object
Faker::Address.latitude.
-
.mutate_longitude(_) ⇒ Object
Faker::Address.longitude.
-
.mutate_lorem_paragraph(_) ⇒ Object
Faker::Lorem.paragraph.
-
.mutate_lorem_sentence(_) ⇒ Object
Faker::Lorem.sentence.
-
.mutate_lorem_word(_) ⇒ Object
Faker::Lorem.word.
-
.mutate_md5(cell) ⇒ Object
MD5 hash of cell contents.
-
.mutate_phone_ext(_) ⇒ Object
Faker::PhoneNumber.extension.
-
.mutate_phone_number(_) ⇒ Object
Faker::PhoneNumber with punctuation and extensions.
-
.mutate_ugcid(_) ⇒ Object
Six random uppercase letters followed by four random numbers - ex.
-
.mutate_url(_) ⇒ Object
Faker::Internet.url.
-
.mutate_user_name(_) ⇒ Object
Faker::Internet.user_name.
-
.mutate_uuid(_) ⇒ Object
(also: mutate_guid)
UUID.
-
.mutate_zip_code(_) ⇒ Object
Faker::Address.zip_code.
Class Method Details
.list ⇒ Object
22 23 24 25 26 27 |
# File 'lib/fake_pipe/mutator.rb', line 22 def list @list ||= public_methods .map { |m| m.to_s[/^mutate_(\w+)$/, 1] } .select(&:present?) .sort end |
.list_with_comments ⇒ Object
Utility method for outputting available mutators. Only require method source here. Currently used by a ‘rake methods`.
32 33 34 35 |
# File 'lib/fake_pipe/mutator.rb', line 32 def list_with_comments require 'method_source' list.map { |short| [short, public_method("mutate_#{short}").comment.strip] } end |
.mutate(name, cell) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/fake_pipe/mutator.rb', line 13 def mutate(name, cell) mutator_method = "mutate_#{name}" if respond_to? mutator_method public_send(mutator_method, cell) else raise "Mutator named `#{name}` not found. Try one of these: #{list.join(', ')}" end end |
.mutate_address_city(_) ⇒ Object
Faker::Address.city
83 84 85 |
# File 'lib/fake_pipe/mutator.rb', line 83 def mutate_address_city(_) Faker::Address.city end |
.mutate_address_country(_) ⇒ Object
Faker::Address.country
78 79 80 |
# File 'lib/fake_pipe/mutator.rb', line 78 def mutate_address_country(_) Faker::Address.country end |
.mutate_address_line_1(_) ⇒ Object
Faker::Address.street_address
68 69 70 |
# File 'lib/fake_pipe/mutator.rb', line 68 def mutate_address_line_1(_) Faker::Address.street_address end |
.mutate_address_line_2(_) ⇒ Object
Faker::Address.secondary_address
73 74 75 |
# File 'lib/fake_pipe/mutator.rb', line 73 def mutate_address_line_2(_) Faker::Address.secondary_address end |
.mutate_address_postcode(_) ⇒ Object
Faker::Address.postcode
93 94 95 |
# File 'lib/fake_pipe/mutator.rb', line 93 def mutate_address_postcode(_) Faker::Address.postcode end |
.mutate_address_state(_) ⇒ Object
Faker::Address.state
88 89 90 |
# File 'lib/fake_pipe/mutator.rb', line 88 def mutate_address_state(_) Faker::Address.state end |
.mutate_bank_name(_) ⇒ Object
Faker::Bank.name
190 191 192 |
# File 'lib/fake_pipe/mutator.rb', line 190 def mutate_bank_name(_) Faker::Bank.name end |
.mutate_bcrypt_password(_) ⇒ Object
bcrypt password as ‘password’
168 169 170 |
# File 'lib/fake_pipe/mutator.rb', line 168 def mutate_bcrypt_password(_) '400$8$2d$f6ed5a490c441958$67f59aa61bc617849a3280b5e80f78607e53b5aa5807a44ddbc53e804e2e2a99' end |
.mutate_bcrypt_salt(_) ⇒ Object
bcrypt salt used to generate password
173 174 175 |
# File 'lib/fake_pipe/mutator.rb', line 173 def mutate_bcrypt_salt(_) 'au6lOASvp17AGsqkmE7' end |
.mutate_clean_phone_number(_) ⇒ Object
Faker::PhoneNumber 10-digits only
43 44 45 |
# File 'lib/fake_pipe/mutator.rb', line 43 def mutate_clean_phone_number(_) Faker::PhoneNumber.phone_number.gsub(/\D|(^1)/, '')[0, 10] end |
.mutate_company_catch_phrase(_) ⇒ Object
Faker::Company.catch_phrase
113 114 115 |
# File 'lib/fake_pipe/mutator.rb', line 113 def mutate_company_catch_phrase(_) Faker::Company.catch_phrase end |
.mutate_company_name(_) ⇒ Object
Faker::Company.name
108 109 110 |
# File 'lib/fake_pipe/mutator.rb', line 108 def mutate_company_name(_) Faker::Company.name end |
.mutate_email(_) ⇒ Object
Faker email
48 49 50 |
# File 'lib/fake_pipe/mutator.rb', line 48 def mutate_email(_) Faker::Internet.email end |
.mutate_empty_bracket(_) ⇒ Object
an empty bracket ‘[]’ - good for json::array objects
123 124 125 |
# File 'lib/fake_pipe/mutator.rb', line 123 def mutate_empty_bracket(_) '[]' end |
.mutate_empty_curly(_) ⇒ Object
an empty curly brace ‘{}’ - good for json object and array fields
118 119 120 |
# File 'lib/fake_pipe/mutator.rb', line 118 def mutate_empty_curly(_) '{}' end |
.mutate_empty_string(_) ⇒ Object
an empty String
128 129 130 |
# File 'lib/fake_pipe/mutator.rb', line 128 def mutate_empty_string(_) '' end |
.mutate_first_name(_) ⇒ Object
Faker::Name.first_name
148 149 150 |
# File 'lib/fake_pipe/mutator.rb', line 148 def mutate_first_name(_) Faker::Name.first_name end |
.mutate_full_name(_) ⇒ Object
Faker::Name.full_name
158 159 160 |
# File 'lib/fake_pipe/mutator.rb', line 158 def mutate_full_name(_) Faker::Name.name end |
.mutate_last_name(_) ⇒ Object
Faker::Name.last_name
153 154 155 |
# File 'lib/fake_pipe/mutator.rb', line 153 def mutate_last_name(_) Faker::Name.last_name end |
.mutate_latitude(_) ⇒ Object
Faker::Address.latitude
98 99 100 |
# File 'lib/fake_pipe/mutator.rb', line 98 def mutate_latitude(_) Faker::Address.latitude end |
.mutate_longitude(_) ⇒ Object
Faker::Address.longitude
103 104 105 |
# File 'lib/fake_pipe/mutator.rb', line 103 def mutate_longitude(_) Faker::Address.longitude end |
.mutate_lorem_paragraph(_) ⇒ Object
Faker::Lorem.paragraph
133 134 135 |
# File 'lib/fake_pipe/mutator.rb', line 133 def mutate_lorem_paragraph(_) Faker::Lorem.paragraph end |
.mutate_lorem_sentence(_) ⇒ Object
Faker::Lorem.sentence
143 144 145 |
# File 'lib/fake_pipe/mutator.rb', line 143 def mutate_lorem_sentence(_) Faker::Lorem.sentence end |
.mutate_lorem_word(_) ⇒ Object
Faker::Lorem.word
138 139 140 |
# File 'lib/fake_pipe/mutator.rb', line 138 def mutate_lorem_word(_) Faker::Lorem.word end |
.mutate_md5(cell) ⇒ Object
MD5 hash of cell contents
63 64 65 |
# File 'lib/fake_pipe/mutator.rb', line 63 def mutate_md5(cell) cell ? Digest::MD5.base64digest(cell) : cell end |
.mutate_phone_ext(_) ⇒ Object
Faker::PhoneNumber.extension
163 164 165 |
# File 'lib/fake_pipe/mutator.rb', line 163 def mutate_phone_ext(_) Faker::PhoneNumber.extension end |
.mutate_phone_number(_) ⇒ Object
Faker::PhoneNumber with punctuation and extensions
38 39 40 |
# File 'lib/fake_pipe/mutator.rb', line 38 def mutate_phone_number(_) Faker::PhoneNumber.phone_number end |
.mutate_ugcid(_) ⇒ Object
Six random uppercase letters followed by four random numbers - ex. ‘ABCDEF1234’
180 181 182 |
# File 'lib/fake_pipe/mutator.rb', line 180 def mutate_ugcid(_) (ALPHABET.sample(6) + DIGITS.sample(4)).join end |
.mutate_url(_) ⇒ Object
Faker::Internet.url
58 59 60 |
# File 'lib/fake_pipe/mutator.rb', line 58 def mutate_url(_) Faker::Internet.url end |
.mutate_user_name(_) ⇒ Object
Faker::Internet.user_name
53 54 55 |
# File 'lib/fake_pipe/mutator.rb', line 53 def mutate_user_name(_) Faker::Internet.user_name end |
.mutate_uuid(_) ⇒ Object Also known as: mutate_guid
UUID
185 186 187 |
# File 'lib/fake_pipe/mutator.rb', line 185 def mutate_uuid(_) SecureRandom.uuid end |
.mutate_zip_code(_) ⇒ Object
Faker::Address.zip_code
195 196 197 |
# File 'lib/fake_pipe/mutator.rb', line 195 def mutate_zip_code(_) Faker::Address.zip_code end |