search_rails 1.0.9 → 1.1.0

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: 2e4e74bd7d993cd3ce3e32f32cf602f0ebce41d4
4
- data.tar.gz: d72b6ae719a35069fb7f65cd6b7d5e06c3d3d68e
3
+ metadata.gz: c59a09b7ad4c1cccc5922f4ed52f840d7bfde161
4
+ data.tar.gz: 6ed13f78e33e454002211d91563787fd722ece6a
5
5
  SHA512:
6
- metadata.gz: c5952b1690d4ac8ec462f565ba6c9f5eff541236c9dd2bd62405953ecf62888cda36842bbf47493e8abaab7cba4a18f93ec5e8e63381c5c649edcba07e05f56f
7
- data.tar.gz: 8b87ad67800ad5380deb71a65d135ee1422f4ee71714531640e312f6336e827e9a218a1bb592ec1d49b5b9138a8f1766e33dd74fb76e34c4ad2130ce5ad70a71
6
+ metadata.gz: a5f7335fd46127d08ee3f36af938447678ba499e268906ecad9cb227161d47d84c867221e455b734289047b2ca787a9411d25cfcafeb85a4d966b2ee92e91406
7
+ data.tar.gz: 899696ddebf673a0c5885af0dcee2f3c30afaaef1f7a52d9de3b6af12dcda3ef46a321d630a3875fa836d1b4d16db74a3d32bd6725588c9a427d62a0aa42e2be
@@ -1,3 +1,3 @@
1
1
  module SearchRails
2
- VERSION = "1.0.9"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/search_rails.rb CHANGED
@@ -8,19 +8,39 @@ module SearchRails
8
8
  require "fileutils"
9
9
  root = Dir.pwd
10
10
  Dir.chdir(root + '/app')
11
- FileUtils::mkdir_p "search"
12
- puts "Created ".green.bold + '/app/search'.bold
11
+ if File.exists?('search')
12
+ puts 'Already Exists'.bold.green + ' /app/search'.bold
13
+ else
14
+ FileUtils::mkdir_p "search"
15
+ puts "Created ".green.bold + '/app/search'.bold
16
+ end
13
17
  Dir.chdir(root + '/app/search')
14
- File.new "search_module.rb", "w"
15
- puts "Created ".green.bold + '/app/search/search_module.rb'.bold
18
+ if File.exists?('search_module.rb')
19
+ File.open(root + '/app/search/search_module.rb', 'w') {|file| file.truncate(0) }
20
+ puts 'Already Exists'.bold.green + ' /app/search/search_module.rb'.bold
21
+ else
22
+ File.new "search_module.rb", "w"
23
+ puts "Created ".green.bold + '/app/search/search_module.rb'.bold
24
+ end
16
25
  Dir.chdir(root + '/app/controllers')
17
- File.new "searches_controller.rb", "w"
18
- puts "Created ".green.bold + '/app/controllers/searches_controller.rb'.bold
26
+ if File.exists?('searches_controller.rb')
27
+ File.open(root + '/app/controllers/searches_controller.rb', 'w') {|file| file.truncate(0) }
28
+ puts 'Already Exists'.bold.green + ' /app/controllers/searches_controller.rb'.bold
29
+ else
30
+ File.new "searches_controller.rb", "w"
31
+ puts "Created ".green.bold + '/app/controllers/searches_controller.rb'.bold
32
+ end
19
33
  Dir.chdir(root + '/app/models')
20
- File.new "search.rb", "w"
21
- puts 'Created '.green.bold + 'app/models/search.rb'.bold
34
+ if File.exists?('search.rb')
35
+ File.open(root + '/app/models/search.rb', 'w') {|file| file.truncate(0) }
36
+ puts 'Already Exists'.bold.green + ' /app/models/search.rb'.bold
37
+ else
38
+ File.new "search.rb", "w"
39
+ puts 'Created '.green.bold + '/app/models/search.rb'.bold
40
+ end
22
41
  Dir.chdir(root + '/db')
23
- if File.exists?('/migrate')
42
+ if File.exists?('migrate')
43
+ puts 'Already Exists'.bold.green + ' /db/migrate'.bold
24
44
  else
25
45
  FileUtils::mkdir_p "migrate"
26
46
  puts "Created ".green.bold + '/db/migrate'.bold
@@ -131,19 +151,24 @@ module SearchRails
131
151
  Dir.chdir(root + '/db/migrate')
132
152
  require 'date'
133
153
  @time = DateTime.now.strftime('%Y%m%d%H%M%S')
134
- File.new @time + '_create_searches.rb', "w"
135
- File.open(@time + "_create_searches.rb", "a") do |line|
136
- line.puts 'class CreateSearches < ActiveRecord::Migration'
137
- line.puts ' def change'
138
- line.puts ' create_table :searches do |t|'
139
- line.puts ' t.string :search'
140
- line.puts ' t.integer :search_id'
141
- line.puts ' t.timestamps null: false'
142
- line.puts ' end'
143
- line.puts ' end'
144
- line.puts 'end'
154
+ if Dir[root + '/db/migrate/*_create_searches.rb'].count > 0
155
+ file = Dir[root + '/db/migrate/*_create_searches.rb'].first
156
+ puts 'Already Exists '.bold.green + file[38..100].bold
157
+ else
158
+ File.new @time + '_create_searches.rb', "w"
159
+ puts "Created ".green.bold + '/db/migrate/'.bold + @time.bold + '_create_searches.rb'.bold
160
+ File.open(@time + "_create_searches.rb", "a") do |line|
161
+ line.puts 'class CreateSearches < ActiveRecord::Migration'
162
+ line.puts ' def change'
163
+ line.puts ' create_table :searches do |t|'
164
+ line.puts ' t.string :search'
165
+ line.puts ' t.integer :search_id'
166
+ line.puts ' t.timestamps null: false'
167
+ line.puts ' end'
168
+ line.puts ' end'
169
+ line.puts 'end'
170
+ end
145
171
  end
146
- puts "Created ".green.bold + '/db/migrate/'.bold + @time.bold + '_create_searches.rb'.bold
147
172
  Dir.chdir(root)
148
173
  end
149
174
 
@@ -153,19 +178,26 @@ module SearchRails
153
178
  Dir.chdir(root + '/app/controllers')
154
179
  first_line = IO.readlines("application_controller.rb")[0]
155
180
  other_lines = IO.readlines("application_controller.rb")[1..1000000000]
156
- File.open("application_controller.rb", "w") do |line|
157
- line.puts first_line
158
- line.puts ' before_action :check_for_search'
159
- line.puts ''
160
- line.puts ' def check_for_search'
161
- line.puts " $LOAD_PATH.unshift(File.dirname('../app/search'))"
162
- line.puts ' extend SearchModule'
163
- line.puts ' check_for_search'
164
- line.puts ' end'
165
- line.puts ''
166
- line.puts other_lines
181
+ second_line = IO.readlines("application_controller.rb")[1]
182
+
183
+ if second_line.chomp == ' before_action :check_for_search'
184
+ puts 'Already Exists'.bold.green + ' /app/controllers/application_controller.rb'.bold
185
+ else
186
+ FileUtils::mkdir_p "migrate"
187
+ puts "Updated ".green.bold + '/app/controllers/application_controller.rb'.bold
188
+ File.open("application_controller.rb", "w") do |line|
189
+ line.puts first_line
190
+ line.puts ' before_action :check_for_search'
191
+ line.puts ''
192
+ line.puts ' def check_for_search'
193
+ line.puts " $LOAD_PATH.unshift(File.dirname('../app/search'))"
194
+ line.puts ' extend SearchModule'
195
+ line.puts ' check_for_search'
196
+ line.puts ' end'
197
+ line.puts ''
198
+ line.puts other_lines
199
+ end
167
200
  end
168
- puts "Updated ".green.bold + '/app/controllers/application_controller.rb'.bold
169
201
  Dir.chdir(root)
170
202
  end
171
203
 
@@ -186,20 +218,27 @@ module SearchRails
186
218
  Dir.chdir(root + '/config')
187
219
  first_line = IO.readlines("routes.rb")[0]
188
220
  other_lines = IO.readlines("routes.rb")[1..1000000000]
189
- File.open('routes.rb', 'w') do |line|
190
- line.puts first_line
191
- line.puts 'resources :searches do'
192
- line.puts ' member do'
193
- line.puts " get 'clear'"
194
- line.puts ' end'
195
- line.puts 'end'
196
- line.puts other_lines
221
+ second_line = IO.readlines("routes.rb")[1]
222
+ if second_line.chomp == 'resources :searches do'
223
+ puts 'Already Exists'.bold.green + ' /config/routes.rb'.bold
224
+ else
225
+ File.open('routes.rb', 'w') do |line|
226
+ line.puts first_line
227
+ line.puts 'resources :searches do'
228
+ line.puts ' member do'
229
+ line.puts " get 'clear'"
230
+ line.puts ' end'
231
+ line.puts 'end'
232
+ line.puts other_lines
233
+ end
234
+ puts 'Updated '.bold.green + '/config/routes.rb'.bold
197
235
  end
198
236
  Dir.chdir(root)
199
237
  end
200
238
 
201
239
  def run
202
240
  require 'colorize'
241
+ root = Dir.pwd
203
242
 
204
243
  puts "Syntax: 'install OBJECT ATTRIBUTE:TYPE'".bold.on_red
205
244
  command = gets.chomp
@@ -212,19 +251,29 @@ module SearchRails
212
251
  end
213
252
 
214
253
  SearchInstall.new.create_files
215
- SearchInstall.new.write_search_controller
254
+ Dir.chdir(root + '/app/controllers')
255
+ if File.exists?('searches_controller.rb')
256
+ else
257
+ SearchInstall.new.write_search_controller
258
+ end
259
+ Dir.chdir(root + '/app/models')
260
+ if File.exists?('search.rb')
261
+ else
262
+ SearchInstall.new.write_search_model
263
+ end
264
+ Dir.chdir(root + '/app/search')
265
+ if File.exists?('search_module.rb')
266
+ else
267
+ SearchInstall.new.write_search_module(object, attributes)
268
+ end
269
+ Dir.chdir(root)
216
270
  SearchInstall.new.write_application_controller
217
- SearchInstall.new.write_search_model
218
271
  SearchInstall.new.write_migration
219
272
  SearchInstall.new.update_routes
220
- SearchInstall.new.write_search_module(object, attributes)
273
+
221
274
  puts 'Done'.bold
222
275
  puts ''
223
- rescue
224
- puts ''
225
- puts 'Something Has Gone Wrong'.bold.red
226
- puts 'Make Sure You Used The Correct Syntax'.bold.red
227
- puts ''
276
+
228
277
 
229
278
  end
230
279
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - micahnico22
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-23 00:00:00.000000000 Z
11
+ date: 2016-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler