dummy 0.5.2 → 0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +23 -1
- data/README.md +14 -7
- data/lib/dummy/address.rb +2 -2
- data/lib/dummy/core_ext/array.rb +5 -0
- data/lib/dummy/core_ext/string.rb +5 -0
- data/lib/dummy/core_ext.rb +2 -0
- data/lib/dummy/phone_number.rb +4 -2
- data/lib/dummy.rb +3 -21
- data/lib/generators/dummy_generator.rb +5 -3
- data/lib/generators/templates/dummy.rake +1 -1
- metadata +6 -4
data/CHANGELOG.md
CHANGED
@@ -27,7 +27,29 @@ Features:
|
|
27
27
|
|
28
28
|
Features:
|
29
29
|
- added tests for the data generators and rails generator
|
30
|
-
-
|
30
|
+
- small improvements
|
31
31
|
- added documentation
|
32
32
|
|
33
|
+
Fixes:
|
34
|
+
- various minor bugs
|
35
|
+
|
36
|
+
## 0.5.1 (July 29, 2010)
|
37
|
+
|
38
|
+
Fixes:
|
39
|
+
- fixed a bug where magic integers were being returned as strings
|
40
|
+
|
41
|
+
## 0.5.2 (July 30, 2010)
|
42
|
+
|
43
|
+
Features:
|
44
|
+
- added option to manually configure the amount of records to generate for each model
|
45
|
+
|
46
|
+
## 0.6 (July 31, 2010)
|
47
|
+
|
48
|
+
Features:
|
49
|
+
- added option to define the output folder where the YAML files are placed
|
50
|
+
|
51
|
+
Fixes:
|
52
|
+
- Removed unused core extensions (for now)
|
53
|
+
- fixed some outdated tests
|
54
|
+
|
33
55
|
|
data/README.md
CHANGED
@@ -18,8 +18,15 @@ Add the following to the Gemfile of your Rails 3 application:
|
|
18
18
|
Now you have access to the generator:
|
19
19
|
rails generate dummy:data
|
20
20
|
|
21
|
-
You can
|
22
|
-
rails generate dummy:data --base-amount
|
21
|
+
You can change the base amount of records and the growth ratio (what these mean exactly is explained latter on):
|
22
|
+
rails generate dummy:data --base-amount 5 --growth-ratio 1.5
|
23
|
+
|
24
|
+
Also, you can manually define the amount of records to generate for each model (or just accept the defaults):
|
25
|
+
rails generate dummy:data --manual-amounts
|
26
|
+
|
27
|
+
And you can manually set the output folder for the YAML files (which defaults to test/dummy/data):
|
28
|
+
rails generate dummy:data --output-folder test/awesome_fixtures
|
29
|
+
|
23
30
|
|
24
31
|
The fixtures are stored in _test/dummy/_ while a rake file is placed in _lib/tasks/dummy.rake_. It allows you to import the generated data into the database:
|
25
32
|
RAILS_ENV="dummy" rake dummy:data:import
|
@@ -32,11 +39,11 @@ Another less conventional way of using dummy is to directly use its magic data g
|
|
32
39
|
Example:
|
33
40
|
require "dummy"
|
34
41
|
|
35
|
-
Dummy.magic_data("mail", :string) => "nyasia@hotmail.com"
|
36
|
-
Dummy.magic_data("company_motto", :string) => "engineer intuitive functionalities"
|
37
|
-
Dummy.magic_data("state", :string) => "Louisiana"
|
38
|
-
Dummy.magic_data("lat", :float) => -86.718683637
|
39
|
-
Dummy.magic_data("phone", :integer) =>
|
42
|
+
Dummy.magic_data("mail", :string) => "nyasia@hotmail.com"
|
43
|
+
Dummy.magic_data("company_motto", :string) => "engineer intuitive functionalities"
|
44
|
+
Dummy.magic_data("state", :string) => "Louisiana"
|
45
|
+
Dummy.magic_data("lat", :float) => -86.718683637
|
46
|
+
Dummy.magic_data("phone", :integer) => 9462876293
|
40
47
|
|
41
48
|
|
42
49
|
## More information
|
data/lib/dummy/address.rb
CHANGED
@@ -3,7 +3,7 @@ module Dummy
|
|
3
3
|
extend self
|
4
4
|
|
5
5
|
def zip_code
|
6
|
-
|
6
|
+
ZIP_FORMATS.rand.numerify
|
7
7
|
end
|
8
8
|
|
9
9
|
def us_state
|
@@ -28,7 +28,7 @@ module Dummy
|
|
28
28
|
def street_address
|
29
29
|
str = ("#" * rand(3)) << "### #{street_name}"
|
30
30
|
|
31
|
-
|
31
|
+
str.numerify
|
32
32
|
end
|
33
33
|
|
34
34
|
def neighborhood
|
data/lib/dummy/phone_number.rb
CHANGED
@@ -3,7 +3,7 @@ module Dummy
|
|
3
3
|
extend self
|
4
4
|
|
5
5
|
def phone_number
|
6
|
-
|
6
|
+
format = case rand(20)
|
7
7
|
when 0 then "###-###-#### x#####"
|
8
8
|
when 1 then "###-###-#### x####"
|
9
9
|
when 2 then "###-###-#### x###"
|
@@ -21,10 +21,12 @@ module Dummy
|
|
21
21
|
when 17 then "1-###-###-#### x###"
|
22
22
|
when 18..19 then "1-###-###-####"
|
23
23
|
end
|
24
|
+
|
25
|
+
format.numerify
|
24
26
|
end
|
25
27
|
|
26
28
|
def phone_number_short
|
27
|
-
|
29
|
+
"###-###-####".numerify
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
data/lib/dummy.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "rubygems"
|
2
|
+
require "dummy/core_ext"
|
2
3
|
require "dummy/address"
|
3
4
|
require "dummy/company"
|
4
5
|
require "dummy/internet"
|
@@ -10,18 +11,6 @@ require "generators/dummy_generator"
|
|
10
11
|
|
11
12
|
module Dummy
|
12
13
|
class << self
|
13
|
-
|
14
|
-
def numerify(number_string)
|
15
|
-
number_string.gsub(/#/) { rand(10).to_s }
|
16
|
-
end
|
17
|
-
|
18
|
-
def letterify(letter_string)
|
19
|
-
letter_string.gsub(/\?/) { ("a".."z").to_a.rand }
|
20
|
-
end
|
21
|
-
|
22
|
-
def bothify(string)
|
23
|
-
letterify(numerify(string))
|
24
|
-
end
|
25
14
|
|
26
15
|
def magic_data(field, type)
|
27
16
|
case type
|
@@ -122,7 +111,7 @@ module Dummy
|
|
122
111
|
(z = z.to_i + 10000) if z[0] == "0"
|
123
112
|
z.to_i
|
124
113
|
when /street|road|address|residence|residency/
|
125
|
-
|
114
|
+
(("#" * rand(3)) << "###").numerify.to_i
|
126
115
|
else
|
127
116
|
rand(1000)
|
128
117
|
end
|
@@ -147,15 +136,8 @@ module Dummy
|
|
147
136
|
when /^(.*[-_:+ ])*(lon|lng)/ then
|
148
137
|
Dummy::Geolocation.lng
|
149
138
|
else
|
150
|
-
|
139
|
+
(("#" * rand(4)) << "#.#" << ("#" * rand(8))).numerify.to_f
|
151
140
|
end
|
152
141
|
end
|
153
142
|
end
|
154
143
|
end
|
155
|
-
|
156
|
-
class Array
|
157
|
-
def rand
|
158
|
-
self[super(self.length)]
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
@@ -15,6 +15,8 @@ module Dummy
|
|
15
15
|
:desc => "The growth ratio of each model, according to its associations."
|
16
16
|
class_option :manual_amounts, :type => :boolean, :default => false,
|
17
17
|
:desc => "Manually set the amount of records for each model."
|
18
|
+
class_option :output_folder, :type => :string, :default => "test/dummy/data",
|
19
|
+
:desc => "Folder to use when outputting the resulting YAML files."
|
18
20
|
|
19
21
|
def install_dummy
|
20
22
|
initialize_application
|
@@ -111,7 +113,7 @@ module Dummy
|
|
111
113
|
end
|
112
114
|
|
113
115
|
def generate_and_write_data
|
114
|
-
empty_directory
|
116
|
+
empty_directory options.output_folder
|
115
117
|
data = Hash.new
|
116
118
|
|
117
119
|
@models.each do |model, info|
|
@@ -138,7 +140,7 @@ module Dummy
|
|
138
140
|
|
139
141
|
content << YAML.dump(fixtures)
|
140
142
|
|
141
|
-
create_file "
|
143
|
+
create_file "#{options.output_folder}/#{name}.yml", content
|
142
144
|
end
|
143
145
|
say_status :successful, "store fixtures"
|
144
146
|
end
|
@@ -185,7 +187,7 @@ module Dummy
|
|
185
187
|
end
|
186
188
|
|
187
189
|
def copy_rake_file
|
188
|
-
|
190
|
+
template "dummy.rake", "lib/tasks/dummy.rake"
|
189
191
|
end
|
190
192
|
end
|
191
193
|
end
|
@@ -5,7 +5,7 @@ namespace :dummy do
|
|
5
5
|
desc "Load the generated dummy data into the current environment's database."
|
6
6
|
task :import => :environment do
|
7
7
|
Fixtures.reset_cache
|
8
|
-
fixtures_folder = File.join(Rails.root,
|
8
|
+
fixtures_folder = File.join(Rails.root, "<%= options.output_folder %>")
|
9
9
|
fixtures = Dir[File.join(fixtures_folder, '*.yml')].map {|f| File.basename(f, '.yml') }
|
10
10
|
Fixtures.create_fixtures(fixtures_folder, fixtures)
|
11
11
|
end
|
metadata
CHANGED
@@ -4,9 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
|
9
|
-
version: 0.5.2
|
7
|
+
- 6
|
8
|
+
version: "0.6"
|
10
9
|
platform: ruby
|
11
10
|
authors:
|
12
11
|
- "Gon\xC3\xA7alo Silva"
|
@@ -14,7 +13,7 @@ autorequire:
|
|
14
13
|
bindir: bin
|
15
14
|
cert_chain: []
|
16
15
|
|
17
|
-
date: 2010-07-
|
16
|
+
date: 2010-07-31 00:00:00 +01:00
|
18
17
|
default_executable:
|
19
18
|
dependencies:
|
20
19
|
- !ruby/object:Gem::Dependency
|
@@ -43,10 +42,13 @@ extensions: []
|
|
43
42
|
extra_rdoc_files: []
|
44
43
|
|
45
44
|
files:
|
45
|
+
- lib/dummy/core_ext.rb
|
46
46
|
- lib/dummy/lorem.rb
|
47
47
|
- lib/dummy/address.rb
|
48
48
|
- lib/dummy/company.rb
|
49
49
|
- lib/dummy/name.rb
|
50
|
+
- lib/dummy/core_ext/string.rb
|
51
|
+
- lib/dummy/core_ext/array.rb
|
50
52
|
- lib/dummy/internet.rb
|
51
53
|
- lib/dummy/geolocation.rb
|
52
54
|
- lib/dummy/phone_number.rb
|