seed_me_seymour 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/lib/seed_me_seymour/version.rb +1 -1
- data/lib/seed_me_seymour.rb +142 -135
- data/seed_me_seymour.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7ed6fce6a415a226512ba3b5480f97213f1e6e6f
|
|
4
|
+
data.tar.gz: 2ed99771f95b34e2c3e3adda1a6a69415bc47eae
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4abda7af090b275a08aa4e4f253dc13d54d44685771b60be0f8c2a158beb9111db7baa0fd712474ab4ef22fe3cd93cf68904a60a52f0bb93012c9aad02d5424
|
|
7
|
+
data.tar.gz: 40866f6615251509605be3a2d821a784716329787b5d46355db668af537bad6bdbcb1215c95d991caeee84a9a3ea75207fe8a05d750019036bcf38200a236b35
|
data/lib/seed_me_seymour.rb
CHANGED
|
@@ -3,141 +3,148 @@ require 'active_support/inflector'
|
|
|
3
3
|
require 'rails/engine'
|
|
4
4
|
|
|
5
5
|
module SeedMeSeymour
|
|
6
|
-
puts "The code for the SMS's main functionality is commented below. It is current as of 2017/24/04 and is meant to be
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
|
|
15
|
-
#
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
#
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
#
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
#
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
#
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
#
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
#
|
|
45
|
-
|
|
46
|
-
#
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
#
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
#
|
|
56
|
-
|
|
57
|
-
#
|
|
58
|
-
|
|
59
|
-
#
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
#
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
#
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
#
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
#
|
|
78
|
-
#
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
#
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
#
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
#
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
#
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
#
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
#
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
#
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
#
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
6
|
+
# puts "The code for the SMS's main functionality is commented below. It is current as of 2017/24/04 and is meant to be
|
|
7
|
+
# initiated from the rake task - lib/tasks/seed_me_seymour.rake. This gem is in developement, but works on a basic level based on column types
|
|
8
|
+
# in your schema. Future releases will create seed data based on basic fields/tables and more complicated associations."
|
|
9
|
+
namespace :seedme do
|
|
10
|
+
desc "seedme creates a seeds file based on an application's models and those model's column type "
|
|
11
|
+
task :go => :environment do
|
|
12
|
+
# require 'active_support/inflector'
|
|
13
|
+
# require 'rails/engine'
|
|
14
|
+
|
|
15
|
+
#determine the path to file
|
|
16
|
+
path = File.expand_path('../', __FILE__)
|
|
17
|
+
fil_e = File.join(path, '../../db/schema.rb')
|
|
18
|
+
fi_le = File.join(path, '../../db/seeds.rb')
|
|
19
|
+
s = File.open(fil_e)
|
|
20
|
+
#whipe everything from seed file
|
|
21
|
+
File.open(fi_le, 'w') {|file| file.truncate(0) }
|
|
22
|
+
|
|
23
|
+
# set faker code
|
|
24
|
+
boolean = "Faker::Boolean.boolean"
|
|
25
|
+
date = "Faker::Date.forward(23)"
|
|
26
|
+
decimal = "Faker::Number.decimal(2)"
|
|
27
|
+
float = "Faker::Number.decimal(2)"
|
|
28
|
+
integer = "Faker::Number.between(1, 10)"
|
|
29
|
+
#indx referes to references. User references to get index into schema.rb
|
|
30
|
+
indx = "Faker::Number.between(1, 10)"
|
|
31
|
+
string = "Faker::StarWars.character"
|
|
32
|
+
text = "Faker::Lorem.sentences(4)"
|
|
33
|
+
time = "Faker::Time.forward(23, :morning)"
|
|
34
|
+
|
|
35
|
+
#contigent email and password
|
|
36
|
+
email = "Faker::Internet.email"
|
|
37
|
+
password = "'password'"
|
|
38
|
+
|
|
39
|
+
#begin parse though each line of schema.rb
|
|
40
|
+
s.each do |line|
|
|
41
|
+
class_singular = ""
|
|
42
|
+
created_text = ""
|
|
43
|
+
|
|
44
|
+
#if line is a model class
|
|
45
|
+
if line.match(/(?<=create_table\s").*?(?=")/)
|
|
46
|
+
#set model class, singularize, and capitalize
|
|
47
|
+
classes = line.match(/(?<=create_table\s").*?(?=")/)[0]
|
|
48
|
+
class_singular = classes.singularize.capitalize
|
|
49
|
+
#appends to document
|
|
50
|
+
File.open(fi_le, 'a') { |file|
|
|
51
|
+
file.puts "10.times do \n " +
|
|
52
|
+
class_singular + ".create!({"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#if line has a t. and is not a date time
|
|
56
|
+
elsif line.match(/((?<=\s\st.)[a-z]{1,13})/) && line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] != "datetime"
|
|
57
|
+
#set column name
|
|
58
|
+
column = line.match(/\st.[a-z]{1,13}.*(?<=")(.*?)"/)[1]
|
|
59
|
+
#if line is a string
|
|
60
|
+
if line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "string"
|
|
61
|
+
type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "string"
|
|
62
|
+
type = string
|
|
63
|
+
#if column is an email
|
|
64
|
+
if line.match(/\st.[a-z]{1,13}.*(?<=")(.*?)"/)[1] == "email"
|
|
65
|
+
column = "email"
|
|
66
|
+
type = email
|
|
67
|
+
#if column is a password
|
|
68
|
+
elsif line.match(/\st.[a-z]{1,13}.*(?<=")(.*?)"/)[1] == "password"
|
|
69
|
+
column = "password"
|
|
70
|
+
type = password
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
#append to file
|
|
74
|
+
File.open(fi_le, 'a') { |file|
|
|
75
|
+
file.puts column + ": " + type + ", "
|
|
76
|
+
}
|
|
77
|
+
#being looking at the active record types inside individual table
|
|
78
|
+
#if type is a text
|
|
79
|
+
elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "text"
|
|
80
|
+
type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
|
|
81
|
+
type = text
|
|
82
|
+
File.open(fi_le, 'a') { |file|
|
|
83
|
+
file.puts column + ": " + type + ", "
|
|
84
|
+
}
|
|
85
|
+
#if type is a boolean
|
|
86
|
+
elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "boolean"
|
|
87
|
+
type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
|
|
88
|
+
type = boolean
|
|
89
|
+
File.open(fi_le, 'a') { |file|
|
|
90
|
+
file.puts column + ": " + type + ", "
|
|
91
|
+
}
|
|
92
|
+
#if type is a date
|
|
93
|
+
elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "date"
|
|
94
|
+
type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
|
|
95
|
+
type = date
|
|
96
|
+
File.open(fi_le, 'a') { |file|
|
|
97
|
+
file.puts column + ": " + type + ", "
|
|
98
|
+
}
|
|
99
|
+
#if type is a decimal
|
|
100
|
+
elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "decimal"
|
|
101
|
+
type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
|
|
102
|
+
type = decimal
|
|
103
|
+
File.open(fi_le, 'a') { |file|
|
|
104
|
+
file.puts column + ": " + type + ", "
|
|
105
|
+
}
|
|
106
|
+
#if type is a float
|
|
107
|
+
elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "float"
|
|
108
|
+
type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
|
|
109
|
+
type = float
|
|
110
|
+
File.open(fi_le, 'a') { |file|
|
|
111
|
+
file.puts column + ": " + type + ", "
|
|
112
|
+
}
|
|
113
|
+
#if type is an integer
|
|
114
|
+
elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "integer"
|
|
115
|
+
type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
|
|
116
|
+
type = integer
|
|
117
|
+
File.open(fi_le, 'a') { |file|
|
|
118
|
+
file.puts column + ": " + type + ", "
|
|
119
|
+
}
|
|
120
|
+
#if type is a references
|
|
121
|
+
elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "index"
|
|
122
|
+
column = line.match(/\s[t.index].*(?<=")(?<=\s\[")(([a-z]+.\id))/)[1]
|
|
123
|
+
type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
|
|
124
|
+
type = indx
|
|
125
|
+
File.open(fi_le, 'a') { |file|
|
|
126
|
+
file.puts column + ": " + type + ", "
|
|
127
|
+
}
|
|
128
|
+
#if type is a time
|
|
129
|
+
elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "time"
|
|
130
|
+
type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
|
|
131
|
+
type = time
|
|
132
|
+
File.open(fi_le, 'a') { |file|
|
|
133
|
+
file.puts column + ": " + type + ", "
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
end
|
|
137
|
+
#locates the end and appends the correct end to the seed file
|
|
138
|
+
elsif line.match(/\s\s(end)/)
|
|
139
|
+
File.open(fi_le, 'a') { |file|
|
|
140
|
+
file.puts "})
|
|
141
|
+
end
|
|
142
|
+
\n"
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
141
148
|
end
|
|
142
149
|
|
|
143
150
|
|
data/seed_me_seymour.gemspec
CHANGED
|
@@ -8,7 +8,7 @@ require 'seed_me_seymour/version'
|
|
|
8
8
|
|
|
9
9
|
Gem::Specification.new do |spec|
|
|
10
10
|
spec.name = "seed_me_seymour"
|
|
11
|
-
spec.version = '0.1.
|
|
11
|
+
spec.version = '0.1.3'
|
|
12
12
|
spec.authors = ["Tony S.", "Brandon G." ]
|
|
13
13
|
spec.email = ["saric.tony@gmail.com\n", "bmg.oak@gmail.com\n"]
|
|
14
14
|
spec.licenses = ['MIT']
|