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

list() click to toggle source
# 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() click to toggle source

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
mutate(name, cell) click to toggle source
# 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(_) click to toggle source

Faker::Address.city

# File lib/fake_pipe/mutator.rb, line 83
def mutate_address_city(_)
  Faker::Address.city
end
mutate_address_country(_) click to toggle source

Faker::Address.country

# File lib/fake_pipe/mutator.rb, line 78
def mutate_address_country(_)
  Faker::Address.country
end
mutate_address_line_1(_) click to toggle source

Faker::Address.street_address

# File lib/fake_pipe/mutator.rb, line 68
def mutate_address_line_1(_)
  Faker::Address.street_address
end
mutate_address_line_2(_) click to toggle source

Faker::Address.secondary_address

# File lib/fake_pipe/mutator.rb, line 73
def mutate_address_line_2(_)
  Faker::Address.secondary_address
end
mutate_address_postcode(_) click to toggle source

Faker::Address.postcode

# File lib/fake_pipe/mutator.rb, line 93
def mutate_address_postcode(_)
  Faker::Address.postcode
end
mutate_address_state(_) click to toggle source

Faker::Address.state

# File lib/fake_pipe/mutator.rb, line 88
def mutate_address_state(_)
  Faker::Address.state
end
mutate_bank_name(_) click to toggle source

Faker::Bank.name

# File lib/fake_pipe/mutator.rb, line 190
def mutate_bank_name(_)
  Faker::Bank.name
end
mutate_bcrypt_password(_) click to toggle source

bcrypt password as 'password'

# File lib/fake_pipe/mutator.rb, line 168
def mutate_bcrypt_password(_)
  '400$8$2d$f6ed5a490c441958$67f59aa61bc617849a3280b5e80f78607e53b5aa5807a44ddbc53e804e2e2a99'
end
mutate_bcrypt_salt(_) click to toggle source

bcrypt salt used to generate password

# File lib/fake_pipe/mutator.rb, line 173
def mutate_bcrypt_salt(_)
  'au6lOASvp17AGsqkmE7'
end
mutate_clean_phone_number(_) click to toggle source

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
mutate_company_catch_phrase(_) click to toggle source

Faker::Company.catch_phrase

# File lib/fake_pipe/mutator.rb, line 113
def mutate_company_catch_phrase(_)
  Faker::Company.catch_phrase
end
mutate_company_name(_) click to toggle source

Faker::Company.name

# File lib/fake_pipe/mutator.rb, line 108
def mutate_company_name(_)
  Faker::Company.name
end
mutate_email(_) click to toggle source

Faker email

# File lib/fake_pipe/mutator.rb, line 48
def mutate_email(_)
  Faker::Internet.email
end
mutate_empty_bracket(_) click to toggle source

an empty bracket '[]' - good for json::array objects

# File lib/fake_pipe/mutator.rb, line 123
def mutate_empty_bracket(_)
  '[]'
end
mutate_empty_curly(_) click to toggle source

an empty curly brace '{}' - good for json object and array fields

# File lib/fake_pipe/mutator.rb, line 118
def mutate_empty_curly(_)
  '{}'
end
mutate_empty_string(_) click to toggle source

an empty String

# File lib/fake_pipe/mutator.rb, line 128
def mutate_empty_string(_)
  ''
end
mutate_first_name(_) click to toggle source

Faker::Name.first_name

# File lib/fake_pipe/mutator.rb, line 148
def mutate_first_name(_)
  Faker::Name.first_name
end
mutate_full_name(_) click to toggle source

Faker::Name.full_name

# File lib/fake_pipe/mutator.rb, line 158
def mutate_full_name(_)
  Faker::Name.name
end
mutate_last_name(_) click to toggle source

Faker::Name.last_name

# File lib/fake_pipe/mutator.rb, line 153
def mutate_last_name(_)
  Faker::Name.last_name
end
mutate_latitude(_) click to toggle source

Faker::Address.latitude

# File lib/fake_pipe/mutator.rb, line 98
def mutate_latitude(_)
  Faker::Address.latitude
end
mutate_longitude(_) click to toggle source

Faker::Address.longitude

# File lib/fake_pipe/mutator.rb, line 103
def mutate_longitude(_)
  Faker::Address.longitude
end
mutate_lorem_paragraph(_) click to toggle source

Faker::Lorem.paragraph

# File lib/fake_pipe/mutator.rb, line 133
def mutate_lorem_paragraph(_)
  Faker::Lorem.paragraph
end
mutate_lorem_sentence(_) click to toggle source

Faker::Lorem.sentence

# File lib/fake_pipe/mutator.rb, line 143
def mutate_lorem_sentence(_)
  Faker::Lorem.sentence
end
mutate_lorem_word(_) click to toggle source

Faker::Lorem.word

# File lib/fake_pipe/mutator.rb, line 138
def mutate_lorem_word(_)
  Faker::Lorem.word
end
mutate_md5(cell) click to toggle source

MD5 hash of cell contents

# File lib/fake_pipe/mutator.rb, line 63
def mutate_md5(cell)
  cell ? Digest::MD5.base64digest(cell) : cell
end
mutate_phone_ext(_) click to toggle source

Faker::PhoneNumber.extension

# File lib/fake_pipe/mutator.rb, line 163
def mutate_phone_ext(_)
  Faker::PhoneNumber.extension
end
mutate_phone_number(_) click to toggle source

Faker::PhoneNumber with punctuation and extensions

# File lib/fake_pipe/mutator.rb, line 38
def mutate_phone_number(_)
  Faker::PhoneNumber.phone_number
end
mutate_ugcid(_) click to toggle source

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
mutate_url(_) click to toggle source

Faker::Internet.url

# File lib/fake_pipe/mutator.rb, line 58
def mutate_url(_)
  Faker::Internet.url
end
mutate_user_name(_) click to toggle source

Faker::Internet.user_name

# File lib/fake_pipe/mutator.rb, line 53
def mutate_user_name(_)
  Faker::Internet.user_name
end
mutate_uuid(_) click to toggle source

UUID

# File lib/fake_pipe/mutator.rb, line 185
def mutate_uuid(_)
  SecureRandom.uuid
end
mutate_zip_code(_) click to toggle source

Faker::Address.zip_code

# File lib/fake_pipe/mutator.rb, line 195
def mutate_zip_code(_)
  Faker::Address.zip_code
end