imposter 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,17 +1,22 @@
1
- = imposter
2
-
3
- Description goes here.
4
-
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2009 Robert Hall. See LICENSE for details.
1
+ = Imposter
2
+
3
+ Real fake data. Allows creation of an entire schema of fake data that honors associations.
4
+
5
+ == Usage
6
+ * script/generate imposter => /test/imposter/[timestamp]_[model].yaml #YAML DSLs for the fake data generation
7
+ # YAMLs are executed in series order much like migrations
8
+ * rake::imposter IMPOSTER="products" #generate only the /test/fixtures/products.csv
9
+ * rake::imposter #generate all /test/imposter/[##############_]*.yaml to /test/fixtures
10
+ * rake::imposter --force #generate all /test/imposter/[###]-*.yaml to /test/fixtures to
11
+ * overwrite any existing .csv
12
+
13
+ * Imposter::Noun.noun => "apple" #random noun
14
+ * Imposter::Verb.verbs(3) => "run tag jump" #random verbs string space delimited
15
+
16
+ #---For unit/integration/etl testing that require real but random addresses
17
+ * Imposter::CSZ.zip => "90210" #random real postal code
18
+ * Imposter::CSZ.city(:zip=>"90210") => "Beverly Hills" #real city name from zip
19
+ * Imposter::CSZ.state_abbr(:zip=>"90210") => "CA" #real 2 letter state abbreviation upper case
20
+ * Imposter::CSZ.state_name(:zip=>"90210") => "California" #Real State name Camelized
21
+
22
+ * Imposter::CSZ.zip(:state_abbr=>"CA") => "90115" #Random but real postal code from real state.
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ begin
14
14
  gem.add_dependency "sqlite3-ruby", ">= 1.2.5"
15
15
  gem.add_dependency "faker", ">= 0"
16
16
  gem.add_dependency "fastercsv", ">= 0"
17
- gem.files.include %w(lib/imposter/*.rb lib/imposter/*.db generators/**/*.rb lib/tasks/**/*.rake)
17
+ gem.files.include %w(lib/imposter/*.rb lib/imposter/*.db generators/**/*.rb generators/templates/*.rake)
18
18
  gem.summary = %Q{Real fake data}
19
19
  gem.description = %Q{Add generator and rake tasks via YAML based imposters for schema level data faking}
20
20
  gem.email = "robert.hall@itatc.com"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -9,79 +9,87 @@ class ImposterGenerator < Rails::Generator::Base
9
9
  conn = ActiveRecord::Base.establish_connection(dbc["development"])
10
10
 
11
11
  def manifest
12
- record do |m|
12
+ record do |m|
13
+ m.directory("test/imposter")
14
+ m.file("databases.rake", "lib/tasks/database.rake")
15
+ puts "Collision Forced " + (options[:collision] == :force).to_s
13
16
  puts "Generating"
14
- if not File.directory? "test/imposter"
15
- Dir.mkdir("test/imposter")
16
- end
17
- case ARGV.length
18
- when 1
19
- genmodel(ARGV[0])
20
- else
21
- genmodels
22
- end
17
+ genmodels
23
18
  end
24
19
  end
25
20
 
26
21
 
27
22
  def genmodel(model_name)
28
- mn = Pathname.new(model_name).basename.to_s.chomp(File.extname(model_name))
23
+ mn = Pathname.new(model_name).basename.to_s.chomp(File.extname(model_name))
29
24
  require model_name
30
- puts " " + mn
31
- mh = Hash.new
32
- ma = Hash.new
33
- mf = Hash.new
34
- eval(mn.camelcase).columns.each do |mod|
35
- if mod.name.include? "_id" then
36
- vl = "@" + mod.name.sub("_id","").pluralize + "[rand(@" + mod.name.sub('_id','').pluralize + ".length)][1]"
37
- mh = {mod.name => vl}
38
- ma.merge!(mh)
39
- else
40
- case mod.type.to_s.downcase
41
- when 'string'
42
- case (1 + rand(3))
43
- when 1
44
- vl = 'Imposter::Noun.multiple'
45
- when 2
46
- vl = 'Imposter::Animal.one'
47
- when 3
48
- vl = 'Imposter::Vegtable.multiple'
49
- when 4
50
- vl = 'Imposter::Mineral.one'
51
- end
52
- when 'text' then
53
- vl = 'Faker::Lorem.sentence(3)'
54
- when 'integer' then
55
- vl = 'i.to_s'
56
- when 'datetime' || 'date'
57
- vl = 'Date.today.to_s'
58
- when 'decimal' then
59
- vl = 'rand(50).to_s + "." + (1000+rand(2000)).to_s'
60
- else
61
- puts "=-------=============> " + mod.type.to_s.downcase
62
- end
63
- if not mod.name.include? "_at" and :include_special
25
+
26
+ yaml_file = "test/imposter/" + "%03d" % eval(mn.camelcase).reflections.count + "-" + mn + ".yml"
27
+ if (not File.exists? yaml_file) || options[:collision] == :force then
28
+ puts " " + mn
29
+ mh = Hash.new
30
+ ma = Hash.new
31
+ mf = Hash.new
32
+ eval(mn.camelcase).columns.each do |mod|
33
+ if mod.name.include? "_id" then
34
+ vl = "@" + mod.name.sub("_id","").pluralize + "[rand(@" + mod.name.sub('_id','').pluralize + ".length)][1]"
64
35
  mh = {mod.name => vl}
65
36
  ma.merge!(mh)
37
+ else
38
+ case mod.type.to_s.downcase
39
+ when 'string'
40
+ case (1 + rand(3))
41
+ when 1
42
+ vl = 'Imposter::Noun.multiple'
43
+ when 2
44
+ vl = 'Imposter::Animal.one'
45
+ when 3
46
+ vl = 'Imposter::Vegtable.multiple'
47
+ when 4
48
+ vl = 'Imposter::Mineral.one'
49
+ end
50
+ when 'text' then
51
+ vl = 'Faker::Lorem.sentence(3)'
52
+ when 'integer' then
53
+ vl = 'i.to_s'
54
+ when 'datetime' || 'date'
55
+ vl = 'Date.today.to_s'
56
+ when 'decimal' then
57
+ vl = 'rand(50).to_s + "." + (1000+rand(2000)).to_s'
58
+ else
59
+ puts "=-------=============> " + mod.type.to_s.downcase
60
+ end
61
+ if not mod.name.include? "_at" and :include_special
62
+ mh = {mod.name => vl}
63
+ ma.merge!(mh)
64
+ end
66
65
  end
67
66
  end
68
- end
69
- mf.merge!(mn => {"fields" => ma})
70
- mf[mn].merge!({"quantity" => 10})
71
- File.open("test/imposter/" + "%03d" % eval(mn.camelcase).reflections.count + "-" + mn + ".yml","w") do |out|
72
- #+ Time.now.strftime("%Y%m%d%H%m%s") + "_" + mn + ".yaml","w") do |out|
73
- YAML.dump(mf,out)
67
+ mf.merge!(mn => {"fields" => ma})
68
+ mf[mn].merge!({"quantity" => 10})
69
+ File.open("test/imposter/" + "%03d" % eval(mn.camelcase).reflections.count + "-" + mn + ".yml","w") do |out|
70
+ YAML.dump(mf,out)
71
+ end
72
+ else
73
+ puts " " + mn + " --skipped"
74
74
  end
75
75
  end
76
76
 
77
77
  def genmodels
78
- create_rake_file
78
+ #create_rake_file
79
79
  models_dir = Dir.glob("app/models/*.rb")
80
80
  models_dir.each do |model_dir|
81
81
  genmodel(model_dir)
82
82
  end
83
83
  end
84
84
 
85
+ def banner
86
+ "Usage: #{$0} #{spec.name} [options]"
87
+ end
88
+
89
+ def add_options!(opt)
90
+ opt.on('-f', '--force') { |value| options[:force] = value }
91
+ end
92
+
85
93
  def create_rake_file
86
94
  puts "Creating lib/tasks/databases.rake"
87
95
  File.copy( Pathname.new(__FILE__).dirname + "../lib/tasks/databases.rake", "lib/tasks/")
File without changes
data/imposter.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{imposter}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Robert Hall"]
12
- s.date = %q{2009-12-09}
12
+ s.date = %q{2009-12-11}
13
13
  s.description = %q{Add generator and rake tasks via YAML based imposters for schema level data faking}
14
14
  s.email = %q{robert.hall@itatc.com}
15
15
  s.extra_rdoc_files = [
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "generators/imposter_generator.rb",
27
+ "generators/templates/databases.rake",
27
28
  "id_rsa.pub",
28
29
  "imposter.gemspec",
29
30
  "lib/imposter.rb",
@@ -38,7 +39,6 @@ Gem::Specification.new do |s|
38
39
  "lib/imposter/verb.rb",
39
40
  "lib/imposter/verb.xx",
40
41
  "lib/imposter/version.rb",
41
- "lib/tasks/databases.rake",
42
42
  "test/helper.rb",
43
43
  "test/test_imposter.rb"
44
44
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imposter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Hall
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-09 00:00:00 -05:00
12
+ date: 2009-12-11 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -79,6 +79,7 @@ files:
79
79
  - Rakefile
80
80
  - VERSION
81
81
  - generators/imposter_generator.rb
82
+ - generators/templates/databases.rake
82
83
  - id_rsa.pub
83
84
  - imposter.gemspec
84
85
  - lib/imposter.rb
@@ -93,7 +94,6 @@ files:
93
94
  - lib/imposter/verb.rb
94
95
  - lib/imposter/verb.xx
95
96
  - lib/imposter/version.rb
96
- - lib/tasks/databases.rake
97
97
  - test/helper.rb
98
98
  - test/test_imposter.rb
99
99
  has_rdoc: true