seed_me_seymour 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 222e4873ff6ef8416b6811db6cc049fe1410f117
4
- data.tar.gz: 21d9f975e5324f8742974c51983dd04f9251775e
3
+ metadata.gz: da3f8e35ae85524f1ade1d76ed3f104abec2cf90
4
+ data.tar.gz: b7714e29229e221cc052b63dfbe8314ef6647f6e
5
5
  SHA512:
6
- metadata.gz: aaf8400e00b03105c3fadfc728daabb4518dca6885ba0f181c103c8bab853a926dbd1c0d8bccfa0542fe7bf4f6c5daccadf0a6a34dddc96611ba8971e424a31f
7
- data.tar.gz: f239dedbe1c8a1fb4531e6e6da974187014d0aad3364dde0ddbde4f8977d820ab835f40341a07d354d678c44a76b6bfc844136ec1b108dd6a24c9112ef859e72
6
+ metadata.gz: f8689fcf32bdd80aa303d96ad00a9a5b52b60f84cd61eb9a4b068b326bdfd241020fd30c27c50aa782b5d4d89869c312047f348ca2709fbf5387d420c5308e60
7
+ data.tar.gz: 93a181ecee6f8e31e81dd22c58f4e4a125d33e2b4c273e6c458af022beef0061fdcf27da24d9e549a63cf59ce1fc687124931e27bdb53a4dd2f91469a3494048
data/Rakefile CHANGED
@@ -1,12 +1,18 @@
1
1
  require_relative 'config/application'
2
+ require 'active_support/inflector'
3
+ require 'rails/engine'
2
4
 
3
- Rails.application.load_tasks
5
+ # Rails.application.load_tasks
4
6
 
5
7
  namespace :seedme do
6
8
  desc "seedme creates a seeds file based on an application's models and those model's column type "
7
- task :go => :environment do
8
- require 'active_support/inflector'
9
- require 'rails/engine'
9
+ task :go do
10
+
11
+ # leaving this code in case we need the :environment do and next two lines. they're currently at top and task excludes the environment
12
+ # task :go => :environment do
13
+ # require 'active_support/inflector'
14
+ # require 'rails/engine'
15
+
10
16
 
11
17
  #determine the path to file
12
18
  path = File.expand_path('../', __FILE__)
@@ -1,3 +1,3 @@
1
1
  module SeedMeSeymour
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -11,6 +11,149 @@ module SeedMeSeymour
11
11
 
12
12
  end
13
13
 
14
+ namespace :seedme do
15
+ desc "seedme creates a seeds file based on an application's models and those model's column type "
16
+ task :go do
17
+
18
+ # leaving this code in case we need the :environment do and next two lines. they're currently at top and task excludes the environment
19
+ # task :go => :environment do
20
+ # require 'active_support/inflector'
21
+ # require 'rails/engine'
22
+
23
+
24
+ #determine the path to file
25
+ path = File.expand_path('../', __FILE__)
26
+ fil_e = File.join(path, '../../db/schema.rb')
27
+ fi_le = File.join(path, '../../db/seeds.rb')
28
+ s = File.open(fil_e)
29
+ #whipe everything from seed file
30
+ File.open(fi_le, 'w') {|file| file.truncate(0) }
31
+
32
+ # set faker code
33
+ boolean = "Faker::Boolean.boolean"
34
+ date = "Faker::Date.forward(23)"
35
+ decimal = "Faker::Number.decimal(2)"
36
+ float = "Faker::Number.decimal(2)"
37
+ integer = "Faker::Number.between(1, 10)"
38
+ #indx referes to references. User references to get index into schema.rb
39
+ indx = "Faker::Number.between(1, 10)"
40
+ string = "Faker::StarWars.character"
41
+ text = "Faker::Lorem.sentences(4)"
42
+ time = "Faker::Time.forward(23, :morning)"
43
+
44
+ #contigent email and password
45
+ email = "Faker::Internet.email"
46
+ password = "'password'"
47
+
48
+ #begin parse though each line of schema.rb
49
+ s.each do |line|
50
+ class_singular = ""
51
+ created_text = ""
52
+
53
+ #if line is a model class
54
+ if line.match(/(?<=create_table\s").*?(?=")/)
55
+ #set model class, singularize, and capitalize
56
+ classes = line.match(/(?<=create_table\s").*?(?=")/)[0]
57
+ class_singular = classes.singularize.capitalize
58
+ #appends to document
59
+ File.open(fi_le, 'a') { |file|
60
+ file.puts "10.times do \n " +
61
+ class_singular + ".create!({"
62
+ }
63
+
64
+ #if line has a t. and is not a date time
65
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/) && line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] != "datetime"
66
+ #set column name
67
+ column = line.match(/\st.[a-z]{1,13}.*(?<=")(.*?)"/)[1]
68
+ #if line is a string
69
+ if line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "string"
70
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "string"
71
+ type = string
72
+ #if column is an email
73
+ if line.match(/\st.[a-z]{1,13}.*(?<=")(.*?)"/)[1] == "email"
74
+ column = "email"
75
+ type = email
76
+ #if column is a password
77
+ elsif line.match(/\st.[a-z]{1,13}.*(?<=")(.*?)"/)[1] == "password"
78
+ column = "password"
79
+ type = password
80
+
81
+ end
82
+ #append to file
83
+ File.open(fi_le, 'a') { |file|
84
+ file.puts column + ": " + type + ", "
85
+ }
86
+ #being looking at the active record types inside individual table
87
+ #if type is a text
88
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "text"
89
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
90
+ type = text
91
+ File.open(fi_le, 'a') { |file|
92
+ file.puts column + ": " + type + ", "
93
+ }
94
+ #if type is a boolean
95
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "boolean"
96
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
97
+ type = boolean
98
+ File.open(fi_le, 'a') { |file|
99
+ file.puts column + ": " + type + ", "
100
+ }
101
+ #if type is a date
102
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "date"
103
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
104
+ type = date
105
+ File.open(fi_le, 'a') { |file|
106
+ file.puts column + ": " + type + ", "
107
+ }
108
+ #if type is a decimal
109
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "decimal"
110
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
111
+ type = decimal
112
+ File.open(fi_le, 'a') { |file|
113
+ file.puts column + ": " + type + ", "
114
+ }
115
+ #if type is a float
116
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "float"
117
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
118
+ type = float
119
+ File.open(fi_le, 'a') { |file|
120
+ file.puts column + ": " + type + ", "
121
+ }
122
+ #if type is an integer
123
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "integer"
124
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
125
+ type = integer
126
+ File.open(fi_le, 'a') { |file|
127
+ file.puts column + ": " + type + ", "
128
+ }
129
+ #if type is a references
130
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "index"
131
+ column = line.match(/\s[t.index].*(?<=")(?<=\s\[")(([a-z]+.\id))/)[1]
132
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
133
+ type = indx
134
+ File.open(fi_le, 'a') { |file|
135
+ file.puts column + ": " + type + ", "
136
+ }
137
+ #if type is a time
138
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "time"
139
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
140
+ type = time
141
+ File.open(fi_le, 'a') { |file|
142
+ file.puts column + ": " + type + ", "
143
+ }
144
+
145
+ end
146
+ #locates the end and appends the correct end to the seed file
147
+ elsif line.match(/\s\s(end)/)
148
+ File.open(fi_le, 'a') { |file|
149
+ file.puts "})
150
+ end
151
+ \n"
152
+ }
153
+
154
+ end
155
+ end
156
+ end
14
157
 
15
158
  # File.open(fi_le, 'a') { |file|
16
159
  # file.puts "User.destroy_all"
@@ -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.6'
11
+ spec.version = '0.1.7'
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']
@@ -1,9 +1,5 @@
1
- require_relative '../../config/application'
2
-
3
- # Rails.application.load_tasks
4
-
5
-
6
-
1
+ require_relative 'config/application'
2
+ Rails.application.load_tasks
7
3
  namespace :seedme do
8
4
  desc "seedme creates a seeds file based on an application's models and those model's column type "
9
5
  task :go => :environment do
@@ -12,8 +8,8 @@ namespace :seedme do
12
8
 
13
9
  #determine the path to file
14
10
  path = File.expand_path('../', __FILE__)
15
- fil_e = File.join(path, '../../db/schema.rb')
16
- fi_le = File.join(path, '../../db/seeds.rb')
11
+ fil_e = File.join(path, 'db/schema.rb')
12
+ fi_le = File.join(path, 'db/seeds.rb')
17
13
  s = File.open(fil_e)
18
14
  #whipe everything from seed file
19
15
  File.open(fi_le, 'w') {|file| file.truncate(0) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seed_me_seymour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony S.