faker 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,8 @@
1
- == 0.9.2 2010-12-28
1
+ == 0.9.4 2010-12-29
2
+ * 1 minor bug fix:
3
+ * Stopped getting in the way of Rails' late locale loading
4
+
5
+ == 0.9.3 2010-12-28
2
6
  * 1 minor enhancement:
3
7
  * Added a faker namespace for translations
4
8
 
data/README.md CHANGED
@@ -13,6 +13,19 @@ Usage
13
13
  * Faker::Name.name => "Christophe Bartell"
14
14
  * Faker::Internet.email => "kirsten.greenholt@corkeryfisher.info"
15
15
 
16
+ Usage with Rails
17
+ ----------------
18
+
19
+ If you want to change your locale with Rails from the default of :en, change
20
+ config/application.rb, setting config.i18n.locale to whatever locale you
21
+ want. Change locale rather than default_locale (as suggested by the comments
22
+ in that file) so that I18n's fallbacks will work properly and Faker can use
23
+ the formats and data in en.yml (if there is no Faker localization for your
24
+ locale). If you'd prefer to set default_locale rather than locale, then
25
+ you'll also need to add config.i18n.fallbacks.defaults = [:en] to your
26
+ configuration to make the fallbacks work for Faker.
27
+
28
+
16
29
  Customization
17
30
  ------------
18
31
  Since you may want to make addresses and other types of data look different
@@ -25,6 +25,12 @@ module Faker
25
25
  def bothify(string)
26
26
  letterify(numerify(string))
27
27
  end
28
+
29
+ # Helper for the common approach of grabbing a translation with an array
30
+ # of values and selecting one of them
31
+ def fetch(key)
32
+ I18n.translate("faker.#{key}").rand
33
+ end
28
34
  end
29
35
  end
30
36
  end
@@ -18,25 +18,26 @@ module Faker
18
18
  end
19
19
 
20
20
  def street_address(include_secondary = false)
21
- numerify("#{I18n.translate('faker.address.street_address').rand} #{street_name}#{' ' + secondary_address if include_secondary}")
21
+ numerify("#{fetch('address.street_address')} #{street_name}#{' ' + secondary_address if include_secondary}")
22
22
  end
23
23
 
24
24
  def secondary_address
25
- numerify(I18n.translate('faker.address.secondary_address').rand)
25
+ numerify(fetch('address.secondary_address'))
26
26
  end
27
27
 
28
28
  def zip_code
29
- bothify(I18n.translate('faker.address.postcode').rand).upcase
29
+ bothify(fetch('address.postcode')).upcase
30
30
  end
31
31
  alias_method :zip, :zip_code
32
32
  alias_method :postcode, :zip_code
33
-
34
- %w(street_suffix city_suffix city_prefix state_abbr state country county).each do |meth|
35
- define_method(meth) do
36
- I18n.translate("faker.address.#{meth}").rand
37
- end
38
- end
39
33
 
34
+ def street_suffix; fetch('address.street_suffix'); end
35
+ def city_suffix; fetch('address.city_suffix'); end
36
+ def city_prefix; fetch('address.city_prefix'); end
37
+ def state_abbr; fetch('address.state_abbr'); end
38
+ def state; fetch('address.state'); end
39
+ def country; fetch('address.country'); end
40
+
40
41
  # You can add whatever you want to the locale file, and it will get
41
42
  # caught here... e.g., create a country_code array in your locale,
42
43
  # then you can call #country_code and it will act like #country
@@ -54,7 +55,7 @@ module Faker
54
55
  alias_method :us_state, :state
55
56
  alias_method :us_state_abbr, :state_abbr
56
57
  alias_method :uk_postcode, :zip_code
57
- alias_method :uk_county, :county
58
+ def uk_county; county; end
58
59
 
59
60
  end
60
61
  end
@@ -6,7 +6,7 @@ module Faker
6
6
  end
7
7
 
8
8
  def suffix
9
- I18n.translate('faker.company.suffix').rand
9
+ fetch('company.suffix')
10
10
  end
11
11
 
12
12
  # Generate a buzzword-laden catch phrase.
@@ -6,7 +6,7 @@ module Faker
6
6
  end
7
7
 
8
8
  def free_email(name = nil)
9
- [ user_name(name), I18n.translate('faker.internet.free_email').rand ].join('@')
9
+ [ user_name(name), fetch('internet.free_email') ].join('@')
10
10
  end
11
11
 
12
12
  def user_name(name = nil)
@@ -30,7 +30,7 @@ module Faker
30
30
  end
31
31
 
32
32
  def domain_suffix
33
- I18n.translate('faker.internet.domain_suffix').rand
33
+ fetch('internet.domain_suffix')
34
34
  end
35
35
 
36
36
  def ip_v4_address
@@ -3,16 +3,14 @@ module Faker
3
3
  class << self
4
4
 
5
5
  def name
6
- I18n.translate('faker.name.formats').rand.collect {|meth| self.send(meth) }.join(' ')
6
+ fetch('name.formats').collect {|meth| self.send(meth) }.join(' ')
7
7
  end
8
8
 
9
- # defines methods first_name, last_name, prefix, suffix
10
- (I18n.translate(:faker)[:name].keys - [:formats]).each do |meth|
11
- define_method(meth) do
12
- I18n.translate("faker.name.#{meth}").rand
13
- end
14
- end
15
-
9
+ def first_name; fetch('name.first_name'); end
10
+ def last_name; fetch('name.last_name'); end
11
+ def prefix; fetch('name.prefix'); end
12
+ def suffix; fetch('name.suffix'); end
13
+
16
14
  end
17
15
  end
18
16
  end
@@ -2,7 +2,7 @@ module Faker
2
2
  class PhoneNumber < Base
3
3
  class << self
4
4
  def phone_number
5
- numerify(I18n.translate('faker.phone_number.formats').rand)
5
+ numerify(fetch('phone_number.formats'))
6
6
  end
7
7
  end
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module Faker #:nodoc:
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faker
3
3
  version: !ruby/object:Gem::Version
4
- hash: 61
4
+ hash: 51
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 3
10
- version: 0.9.3
9
+ - 4
10
+ version: 0.9.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Benjamin Curtis
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-28 00:00:00 -08:00
18
+ date: 2010-12-29 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency