Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Shuffling classes around

  • Loading branch information...
commit 510fa94293ab83c7b43d25d9f307dcfd635b6241 1 parent 4f45c90
@stympy stympy authored
View
42 lib/faker.rb
@@ -4,16 +4,6 @@
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
I18n.load_path += Dir[File.join(mydir, 'locales', '*.yml')]
-require 'faker/address'
-require 'faker/company'
-require 'faker/internet'
-require 'faker/lorem'
-require 'faker/name'
-require 'faker/phone_number'
-require 'faker/version'
-
-require 'extensions/array'
-
module Faker
class Config
@@ -22,15 +12,29 @@ def self.locale=(locale)
end
end
- def self.numerify(number_string)
- number_string.gsub(/#/) { rand(10).to_s }
- end
+ class Base
+ class << self
+ def numerify(number_string)
+ number_string.gsub(/#/) { rand(10).to_s }
+ end
- def self.letterify(letter_string)
- letter_string.gsub(/\?/) { ('a'..'z').to_a.rand }
- end
+ def letterify(letter_string)
+ letter_string.gsub(/\?/) { ('a'..'z').to_a.rand }
+ end
- def self.bothify(string)
- self.letterify(self.numerify(string))
+ def bothify(string)
+ letterify(numerify(string))
+ end
+ end
end
-end
+end
+
+require 'faker/address'
+require 'faker/company'
+require 'faker/internet'
+require 'faker/lorem'
+require 'faker/name'
+require 'faker/phone_number'
+require 'faker/version'
+
+require 'extensions/array'
View
8 lib/faker/address.rb
@@ -1,5 +1,5 @@
module Faker
- class Address
+ class Address < Base
class << self
def city
[
@@ -18,15 +18,15 @@ def street_name
end
def street_address(include_secondary = false)
- Faker.numerify("#{I18n.translate('address.street_address').rand} #{street_name}#{' ' + secondary_address if include_secondary}")
+ numerify("#{I18n.translate('address.street_address').rand} #{street_name}#{' ' + secondary_address if include_secondary}")
end
def secondary_address
- Faker.numerify(I18n.translate('address.secondary_address').rand)
+ numerify(I18n.translate('address.secondary_address').rand)
end
def zip_code
- Faker.bothify(I18n.translate('address.postcode').rand).upcase
+ bothify(I18n.translate('address.postcode').rand).upcase
end
alias_method :zip, :zip_code
alias_method :postcode, :zip_code
View
2  lib/faker/company.rb
@@ -1,5 +1,5 @@
module Faker
- class Company
+ class Company < Base
class << self
def name
Formats.rand.call
View
2  lib/faker/internet.rb
@@ -1,5 +1,5 @@
module Faker
- class Internet
+ class Internet < Base
class << self
def email(name = nil)
[ user_name(name), domain_name ].join('@')
View
2  lib/faker/lorem.rb
@@ -1,6 +1,6 @@
module Faker
# Based on Perl's Text::Lorem
- class Lorem
+ class Lorem < Base
def self.words(num = 3)
I18n.translate('lorem.words').shuffle[0, num]
end
View
2  lib/faker/name.rb
@@ -1,5 +1,5 @@
module Faker
- class Name
+ class Name < Base
class << self
def name
View
4 lib/faker/phone_number.rb
@@ -1,8 +1,8 @@
module Faker
- class PhoneNumber
+ class PhoneNumber < Base
class << self
def phone_number
- Faker.numerify(I18n.translate('phone_number.formats').rand)
+ numerify(I18n.translate('phone_number.formats').rand)
end
end
end
View
2  test/test_faker.rb
@@ -6,6 +6,6 @@ def setup
end
def test_numerify
- assert Faker.numerify('###').match(/\d{3}/)
+ assert Faker::Base.numerify('###').match(/\d{3}/)
end
end

0 comments on commit 510fa94

Please sign in to comment.
Something went wrong with that request. Please try again.