seed_me_seymour 0.1.1 → 0.1.2

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: 542497a0c99bb27e73dd4991e7f53c252f6efdd6
4
- data.tar.gz: c8960f1aa383e4625b5b94f83716c3c70388c970
3
+ metadata.gz: 49c51f597df137fc9756e22f0417477c9dcc27f2
4
+ data.tar.gz: df8fc4854cdd9240343a365e6648ca6d0ed10ad5
5
5
  SHA512:
6
- metadata.gz: 835e2545f641cff69dc6feb1417c2d8d22f6360f9ea31dd52e2e5143f261ee0f45212f46c0fd538103b2041038213724917c1b9ea6ae4a2b039eaa2b7b8f6c5a
7
- data.tar.gz: aafea9dc196da89b3279957c4aac84ebb810b7300f678b0dbfed2715fb541b67d74f076fa1ddd0932be8769eebbd941013d727868bbb67bd11b189667099f013
6
+ metadata.gz: 7d3de2e34e7691e0d81e76f004601e2b9d1842133c6b0daf9b4558ff28064b6575d72b90f5f66ef8500f1bca11738af045cc21b8c51a2a2c193286c170aae062
7
+ data.tar.gz: ff7f12b69fb56b6028132de91a9148713a054e3c2d13d6119d8b8dd3a4cd9865ea4bcc381df6e2d1caa7fd63c8b605ac2236625332444c5a5e04ca74266ed633
data/Rakefile CHANGED
@@ -1,3 +1,143 @@
1
1
  require_relative 'config/application'
2
2
 
3
3
  Rails.application.load_tasks
4
+
5
+ namespace :seedme do
6
+ 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'
10
+
11
+ #determine the path to file
12
+ path = File.expand_path('../', __FILE__)
13
+ fil_e = File.join(path, '../../db/schema.rb')
14
+ fi_le = File.join(path, '../../db/seeds.rb')
15
+ s = File.open(fil_e)
16
+ #whipe everything from seed file
17
+ File.open(fi_le, 'w') {|file| file.truncate(0) }
18
+
19
+ # set faker code
20
+ boolean = "Faker::Boolean.boolean"
21
+ date = "Faker::Date.forward(23)"
22
+ decimal = "Faker::Number.decimal(2)"
23
+ float = "Faker::Number.decimal(2)"
24
+ integer = "Faker::Number.between(1, 10)"
25
+ #indx referes to references. User references to get index into schema.rb
26
+ indx = "Faker::Number.between(1, 10)"
27
+ string = "Faker::StarWars.character"
28
+ text = "Faker::Lorem.sentences(4)"
29
+ time = "Faker::Time.forward(23, :morning)"
30
+
31
+ #contigent email and password
32
+ email = "Faker::Internet.email"
33
+ password = "'password'"
34
+
35
+ #begin parse though each line of schema.rb
36
+ s.each do |line|
37
+ class_singular = ""
38
+ created_text = ""
39
+
40
+ #if line is a model class
41
+ if line.match(/(?<=create_table\s").*?(?=")/)
42
+ #set model class, singularize, and capitalize
43
+ classes = line.match(/(?<=create_table\s").*?(?=")/)[0]
44
+ class_singular = classes.singularize.capitalize
45
+ #appends to document
46
+ File.open(fi_le, 'a') { |file|
47
+ file.puts "10.times do \n " +
48
+ class_singular + ".create!({"
49
+ }
50
+
51
+ #if line has a t. and is not a date time
52
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/) && line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] != "datetime"
53
+ #set column name
54
+ column = line.match(/\st.[a-z]{1,13}.*(?<=")(.*?)"/)[1]
55
+ #if line is a string
56
+ if line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "string"
57
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "string"
58
+ type = string
59
+ #if column is an email
60
+ if line.match(/\st.[a-z]{1,13}.*(?<=")(.*?)"/)[1] == "email"
61
+ column = "email"
62
+ type = email
63
+ #if column is a password
64
+ elsif line.match(/\st.[a-z]{1,13}.*(?<=")(.*?)"/)[1] == "password"
65
+ column = "password"
66
+ type = password
67
+
68
+ end
69
+ #append to file
70
+ File.open(fi_le, 'a') { |file|
71
+ file.puts column + ": " + type + ", "
72
+ }
73
+ #being looking at the active record types inside individual table
74
+ #if type is a text
75
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "text"
76
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
77
+ type = text
78
+ File.open(fi_le, 'a') { |file|
79
+ file.puts column + ": " + type + ", "
80
+ }
81
+ #if type is a boolean
82
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "boolean"
83
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
84
+ type = boolean
85
+ File.open(fi_le, 'a') { |file|
86
+ file.puts column + ": " + type + ", "
87
+ }
88
+ #if type is a date
89
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "date"
90
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
91
+ type = date
92
+ File.open(fi_le, 'a') { |file|
93
+ file.puts column + ": " + type + ", "
94
+ }
95
+ #if type is a decimal
96
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "decimal"
97
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
98
+ type = decimal
99
+ File.open(fi_le, 'a') { |file|
100
+ file.puts column + ": " + type + ", "
101
+ }
102
+ #if type is a float
103
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "float"
104
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
105
+ type = float
106
+ File.open(fi_le, 'a') { |file|
107
+ file.puts column + ": " + type + ", "
108
+ }
109
+ #if type is an integer
110
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "integer"
111
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
112
+ type = integer
113
+ File.open(fi_le, 'a') { |file|
114
+ file.puts column + ": " + type + ", "
115
+ }
116
+ #if type is a references
117
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "index"
118
+ column = line.match(/\s[t.index].*(?<=")(?<=\s\[")(([a-z]+.\id))/)[1]
119
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
120
+ type = indx
121
+ File.open(fi_le, 'a') { |file|
122
+ file.puts column + ": " + type + ", "
123
+ }
124
+ #if type is a time
125
+ elsif line.match(/((?<=\s\st.)[a-z]{1,13})/)[0] == "time"
126
+ type = line.match(/((?<=\s\st.)[a-z]{1,13})/)[0]
127
+ type = time
128
+ File.open(fi_le, 'a') { |file|
129
+ file.puts column + ": " + type + ", "
130
+ }
131
+
132
+ end
133
+ #locates the end and appends the correct end to the seed file
134
+ elsif line.match(/\s\s(end)/)
135
+ File.open(fi_le, 'a') { |file|
136
+ file.puts "})
137
+ end
138
+ \n"
139
+ }
140
+
141
+ end
142
+ end
143
+ end
@@ -1,3 +1,3 @@
1
1
  module SeedMeSeymour
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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.1'
11
+ spec.version = '0.1.2'
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']
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony S.