imposter 0.1.6 → 0.1.7
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/VERSION +1 -1
- data/generators/imposter_generator.rb +3 -1
- data/imposter.gemspec +2 -1
- data/lib/imposter.rb +12 -11
- data/lib/imposter/csz.rb +3 -1
- data/lib/imposter/imposter.rb +42 -0
- metadata +2 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
@@ -51,7 +51,9 @@ class ImposterGenerator < Rails::Generator::Base
|
|
51
51
|
vl = 'Faker::Lorem.sentence(3)'
|
52
52
|
when 'integer' then
|
53
53
|
vl = 'i.to_s'
|
54
|
-
when 'datetime'
|
54
|
+
when 'datetime'
|
55
|
+
vl = 'Date.today.to_s'
|
56
|
+
when 'date'
|
55
57
|
vl = 'Date.today.to_s'
|
56
58
|
when 'decimal' then
|
57
59
|
vl = 'rand(50).to_s + "." + (1000+rand(2000)).to_s'
|
data/imposter.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{imposter}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.7"
|
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"]
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/imposter/animal.rb",
|
32
32
|
"lib/imposter/csz.db",
|
33
33
|
"lib/imposter/csz.rb",
|
34
|
+
"lib/imposter/imposter.rb",
|
34
35
|
"lib/imposter/mineral.rb",
|
35
36
|
"lib/imposter/noun.rb",
|
36
37
|
"lib/imposter/phone.rb",
|
data/lib/imposter.rb
CHANGED
@@ -10,7 +10,7 @@ require 'imposter/verb'
|
|
10
10
|
require 'imposter/animal'
|
11
11
|
require 'imposter/vegtable'
|
12
12
|
require 'imposter/mineral'
|
13
|
-
require 'imposter/
|
13
|
+
require 'imposter/csz'
|
14
14
|
|
15
15
|
module Imposter
|
16
16
|
|
@@ -21,7 +21,7 @@ module Imposter
|
|
21
21
|
m = Array.new(cnt,0)
|
22
22
|
FasterCSV.open(filename,"w") do |csv|
|
23
23
|
csv << fields
|
24
|
-
|
24
|
+
begin
|
25
25
|
(1..cnt).each do |i|
|
26
26
|
vl.each do |v|
|
27
27
|
begin
|
@@ -34,9 +34,9 @@ module Imposter
|
|
34
34
|
csv << l
|
35
35
|
l.clear
|
36
36
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
rescue
|
38
|
+
puts "Some format/data error in " + filename
|
39
|
+
end
|
40
40
|
end
|
41
41
|
return m
|
42
42
|
end
|
@@ -44,10 +44,12 @@ module Imposter
|
|
44
44
|
def self.getfixtures
|
45
45
|
fixtures_dir = Dir.glob("test/fixtures/*.csv")
|
46
46
|
#Loading existing CSV structures
|
47
|
-
fixtures_dir.
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
if not fixtures_dir.empty? then
|
48
|
+
fixtures_dir.each do |fixture_csv|
|
49
|
+
fn = Pathname.new(fixture_csv).basename.to_s.chomp(File.extname(fixture_csv))
|
50
|
+
eval("@" + fn + "= FasterCSV.open(fixture_csv,'r').to_a rescue nil")
|
51
|
+
end
|
52
|
+
end
|
51
53
|
end
|
52
54
|
|
53
55
|
def self.parseyaml(yamlfilename)
|
@@ -57,13 +59,12 @@ module Imposter
|
|
57
59
|
imp_values = imp_yaml[mn]["fields"].values
|
58
60
|
imp_fields = imp_yaml[mn]["fields"].keys
|
59
61
|
imp_qty = imp_yaml[mn]["quantity"]
|
60
|
-
#load existing csv as array assigned to @[csv] variable
|
61
|
-
#process yaml to csv
|
62
62
|
rl = gencsv("test/fixtures/" + mn.pluralize + ".csv",imp_qty,imp_fields, imp_values)
|
63
63
|
eval("@" + mn.pluralize + "= rl")
|
64
64
|
end
|
65
65
|
|
66
66
|
def self.genimposters
|
67
|
+
puts "File: " + __FILE__
|
67
68
|
models_dir = Dir.glob("test/imposter/*.yml")
|
68
69
|
#puts models_dir
|
69
70
|
models_dir.each do |imposter_yaml|
|
data/lib/imposter/csz.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'sqlite3'
|
3
|
+
require 'pathname'
|
3
4
|
|
4
|
-
|
5
|
+
db_file = Pathname.new(__FILE__).dirname + "//"
|
6
|
+
$csz_db =SQLite3::Database.new(db_file + "csz.db")
|
5
7
|
$csz_db.results_as_hash = true
|
6
8
|
$total_rows = $csz_db.execute2("select count(*) from us")
|
7
9
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sqlite3'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
db_file = Pathname.new(__FILE__).dirname + "/csz.rb"
|
6
|
+
$csz_db =SQLite3::Database.new("/usr/lib/ruby/gems/1.8/gems/imposter-0.1.6/lib/imposter/csz.rb")
|
7
|
+
$csz_db.results_as_hash = true
|
8
|
+
$total_rows = $csz_db.execute2("select count(*) from us")
|
9
|
+
|
10
|
+
|
11
|
+
module Imposter
|
12
|
+
class CSZ
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def get_rand
|
16
|
+
rand_row = (1+rand($total_rows[1][0].to_i - 1)).to_s
|
17
|
+
@@csz_get = $csz_db.execute2("select city,state,statefull,zip5 from us limit " + rand_row + ",1")[1]
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_rand_state(st=nil)
|
21
|
+
rand_row = (1 + rand($csz_db.execute2("select count(*) from us where upper(state)='"+ st.upcase + "'")[1][0].to_i - 1)).to_s
|
22
|
+
@@csz_get = $csz_db.execute2("select city,state,statefull,zip5 from us where state='" + st.upcase + "' limit " + rand_row + ",1")[1]
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_rand_city(cty = nil)
|
26
|
+
rand_row = (1 + rand($csz_db.execute2("select count(*) from us where upper(city)='"+ cty.upcase + "'")[1][0].to_i - 1)).to_s
|
27
|
+
@@csz_get = $csz_db.execute2("select city,state,statefull,zip5 from us where upper(city)='" + cty.upcase + "' limit " + rand_row + ",1")[1]
|
28
|
+
end
|
29
|
+
|
30
|
+
def zip5
|
31
|
+
@@csz_get['zip5']
|
32
|
+
end
|
33
|
+
def state(zip5=nil)
|
34
|
+
@@csz_get['state']
|
35
|
+
end
|
36
|
+
|
37
|
+
def city(zip5=nil)
|
38
|
+
@@csz_get['city']
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
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.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Hall
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/imposter/animal.rb
|
87
87
|
- lib/imposter/csz.db
|
88
88
|
- lib/imposter/csz.rb
|
89
|
+
- lib/imposter/imposter.rb
|
89
90
|
- lib/imposter/mineral.rb
|
90
91
|
- lib/imposter/noun.rb
|
91
92
|
- lib/imposter/phone.rb
|