module FakePipe::Mutator
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.
Constants
- ALPHABET
- DIGITS
Public Instance Methods
# 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
Utility method for outputting available mutators. Only require method source here. Currently used by a `rake methods`.
# 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
# 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
Faker::Address.city
# File lib/fake_pipe/mutator.rb, line 83 def mutate_address_city(_) Faker::Address.city end
Faker::Address.country
# File lib/fake_pipe/mutator.rb, line 78 def mutate_address_country(_) Faker::Address.country end
Faker::Address.street_address
# File lib/fake_pipe/mutator.rb, line 68 def mutate_address_line_1(_) Faker::Address.street_address end
Faker::Address.secondary_address
# File lib/fake_pipe/mutator.rb, line 73 def mutate_address_line_2(_) Faker::Address.secondary_address end
Faker::Address.postcode
# File lib/fake_pipe/mutator.rb, line 93 def mutate_address_postcode(_) Faker::Address.postcode end
Faker::Address.state
# File lib/fake_pipe/mutator.rb, line 88 def mutate_address_state(_) Faker::Address.state end
Faker::Bank.name
# File lib/fake_pipe/mutator.rb, line 190 def mutate_bank_name(_) Faker::Bank.name end
bcrypt password as 'password'
# File lib/fake_pipe/mutator.rb, line 168 def mutate_bcrypt_password(_) '400$8$2d$f6ed5a490c441958$67f59aa61bc617849a3280b5e80f78607e53b5aa5807a44ddbc53e804e2e2a99' end
bcrypt salt used to generate password
# File lib/fake_pipe/mutator.rb, line 173 def mutate_bcrypt_salt(_) 'au6lOASvp17AGsqkmE7' end
Faker::PhoneNumber 10-digits only
# File lib/fake_pipe/mutator.rb, line 43 def mutate_clean_phone_number(_) Faker::PhoneNumber.phone_number.gsub(/\D|(^1)/, '')[0, 10] end
Faker::Company.catch_phrase
# File lib/fake_pipe/mutator.rb, line 113 def mutate_company_catch_phrase(_) Faker::Company.catch_phrase end
Faker::Company.name
# File lib/fake_pipe/mutator.rb, line 108 def mutate_company_name(_) Faker::Company.name end
Faker email
# File lib/fake_pipe/mutator.rb, line 48 def mutate_email(_) Faker::Internet.email end
an empty bracket '[]' - good for json::array objects
# File lib/fake_pipe/mutator.rb, line 123 def mutate_empty_bracket(_) '[]' end
an empty curly brace '{}' - good for json object and array fields
# File lib/fake_pipe/mutator.rb, line 118 def mutate_empty_curly(_) '{}' end
an empty String
# File lib/fake_pipe/mutator.rb, line 128 def mutate_empty_string(_) '' end
Faker::Name.first_name
# File lib/fake_pipe/mutator.rb, line 148 def mutate_first_name(_) Faker::Name.first_name end
Faker::Name.full_name
# File lib/fake_pipe/mutator.rb, line 158 def mutate_full_name(_) Faker::Name.name end
Faker::Name.last_name
# File lib/fake_pipe/mutator.rb, line 153 def mutate_last_name(_) Faker::Name.last_name end
Faker::Address.latitude
# File lib/fake_pipe/mutator.rb, line 98 def mutate_latitude(_) Faker::Address.latitude end
Faker::Address.longitude
# File lib/fake_pipe/mutator.rb, line 103 def mutate_longitude(_) Faker::Address.longitude end
Faker::Lorem.paragraph
# File lib/fake_pipe/mutator.rb, line 133 def mutate_lorem_paragraph(_) Faker::Lorem.paragraph end
Faker::Lorem.sentence
# File lib/fake_pipe/mutator.rb, line 143 def mutate_lorem_sentence(_) Faker::Lorem.sentence end
Faker::Lorem.word
# File lib/fake_pipe/mutator.rb, line 138 def mutate_lorem_word(_) Faker::Lorem.word end
MD5 hash of cell contents
# File lib/fake_pipe/mutator.rb, line 63 def mutate_md5(cell) cell ? Digest::MD5.base64digest(cell) : cell end
Faker::PhoneNumber.extension
# File lib/fake_pipe/mutator.rb, line 163 def mutate_phone_ext(_) Faker::PhoneNumber.extension end
Faker::PhoneNumber with punctuation and extensions
# File lib/fake_pipe/mutator.rb, line 38 def mutate_phone_number(_) Faker::PhoneNumber.phone_number end
Six random uppercase letters followed by four random numbers - ex. 'ABCDEF1234'
# File lib/fake_pipe/mutator.rb, line 180 def mutate_ugcid(_) (ALPHABET.sample(6) + DIGITS.sample(4)).join end
Faker::Internet.url
# File lib/fake_pipe/mutator.rb, line 58 def mutate_url(_) Faker::Internet.url end
Faker::Internet.user_name
# File lib/fake_pipe/mutator.rb, line 53 def mutate_user_name(_) Faker::Internet.user_name end
UUID
# File lib/fake_pipe/mutator.rb, line 185 def mutate_uuid(_) SecureRandom.uuid end
Faker::Address.zip_code
# File lib/fake_pipe/mutator.rb, line 195 def mutate_zip_code(_) Faker::Address.zip_code end