search_rails 1.1.3 → 2.0.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 +5 -5
- data/.github/dependabot.yml +15 -0
- data/.github/workflows/ci.yml +38 -0
- data/.gitignore +30 -9
- data/.node-version +1 -0
- data/.npm-version +1 -0
- data/.prettierignore +2 -0
- data/.rspec +1 -2
- data/.rubocop.yml +130 -0
- data/.ruby-version +1 -0
- data/.tool-versions +3 -0
- data/Gemfile +19 -6
- data/Gemfile.lock +398 -0
- data/LICENSE +19 -0
- data/README.md +2 -80
- data/Rakefile +3 -4
- data/VERSION +1 -0
- data/lib/search.rb +667 -0
- data/lib/search_rails.rb +11 -529
- data/package-lock.json +14 -0
- data/package.json +7 -0
- data/search_rails.gemspec +18 -24
- metadata +46 -46
- data/.travis.yml +0 -5
- data/CODE_OF_CONDUCT.md +0 -74
- data/LICENSE.txt +0 -21
- data/bin/console +0 -14
- data/bin/search:install +0 -5
- data/bin/search:install:devise +0 -5
- data/bin/setup +0 -8
- data/lib/search_rails/version.rb +0 -3
data/lib/search_rails.rb
CHANGED
@@ -1,533 +1,15 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
require "fileutils"
|
9
|
-
root = Dir.pwd
|
10
|
-
Dir.chdir(root + '/app')
|
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
|
17
|
-
Dir.chdir(root + '/app/search')
|
18
|
-
if File.exists?('search_module.rb')
|
19
|
-
puts 'Already Exists'.bold.green + ' /app/search/search_module.rb'.bold
|
20
|
-
else
|
21
|
-
File.new "search_module.rb", "w"
|
22
|
-
puts "Created ".green.bold + '/app/search/search_module.rb'.bold
|
23
|
-
end
|
24
|
-
Dir.chdir(root + '/app/controllers')
|
25
|
-
if File.exists?('searches_controller.rb')
|
26
|
-
puts 'Already Exists'.bold.green + ' /app/controllers/searches_controller.rb'.bold
|
27
|
-
else
|
28
|
-
File.new "searches_controller.rb", "w"
|
29
|
-
puts "Created ".green.bold + '/app/controllers/searches_controller.rb'.bold
|
30
|
-
end
|
31
|
-
Dir.chdir(root + '/app/models')
|
32
|
-
if File.exists?('search.rb')
|
33
|
-
puts 'Already Exists'.bold.green + ' /app/models/search.rb'.bold
|
34
|
-
else
|
35
|
-
File.new "search.rb", "w"
|
36
|
-
puts 'Created '.green.bold + '/app/models/search.rb'.bold
|
37
|
-
end
|
38
|
-
Dir.chdir(root + '/db')
|
39
|
-
if File.exists?('migrate')
|
40
|
-
puts 'Already Exists'.bold.green + ' /db/migrate'.bold
|
41
|
-
else
|
42
|
-
FileUtils::mkdir_p "migrate"
|
43
|
-
puts "Created ".green.bold + '/db/migrate'.bold
|
44
|
-
end
|
45
|
-
Dir.chdir(root)
|
46
|
-
end
|
47
|
-
|
48
|
-
def write_search_module(object, attributes)
|
49
|
-
root = Dir.pwd
|
50
|
-
require 'active_support/inflector'
|
51
|
-
Dir.chdir(root + '/app/search')
|
52
|
-
File.open("search_module.rb", "a") do |line|
|
53
|
-
line.puts 'module SearchModule'
|
54
|
-
line.puts ' def search'
|
55
|
-
attri_one = attributes[0]
|
56
|
-
attribute = attri_one.split(':')
|
57
|
-
line.puts " @" + object.downcase.pluralize + " = " + object.capitalize.singularize + ".where('lower(" + attribute[0] + ") LIKE ?', '%' + @search.search.downcase + '%')"
|
58
|
-
attributes = attributes.reject { |attri| attri == attributes[0] }
|
59
|
-
attributes.each do |attri|
|
60
|
-
attribute = attri.split(':')
|
61
|
-
if attribute[1] == 'integer' || attribute[1] == 'decimal'
|
62
|
-
line.puts " " + object.capitalize.singularize + ".where('cast(" + attribute[0] + " AS VARCHAR) LIKE ?', '%' + @search.search + '%').each { |" + attribute[0] + "| @" + object.downcase.pluralize + ".any? { |f| f.id == " + attribute[0] + ".id } ? true : @" + object.downcase.pluralize + " << " + attribute[0] + " }"
|
63
|
-
elsif attribute[1] == 'boolean'
|
64
|
-
line.puts " if @search.search.downcase == 'true' || @search.search.downcase == 'tru' || @search.search.downcase == 'tr' || @search.search.downcase == 't'"
|
65
|
-
line.puts " " + object.capitalize.singularize + ".where(" + attribute[0] + ": true).each { |" + attribute[0] + "| @" + object.downcase.pluralize + ".any? { |f| f.id == " + attribute[0] + ".id } ? true : @" + object.downcase.pluralize + " << " + attribute[0] + " }"
|
66
|
-
line.puts " else @search.search.downcase == 'false' || @search.search.downcase == 'fals' || @search.search.downcase == 'fal' || @search.search.downcase == 'fa' || @search.search.downcase == 'f'"
|
67
|
-
line.puts " " + object.capitalize.singularize + ".where(" + attribute[0] + ": false).each { |" + attribute[0] + "| @" + object.downcase.pluralize + ".any? { |f| f.id == " + attribute[0] + ".id } ? true : @" + object.downcase.pluralize + " << " + attribute[0] + " }"
|
68
|
-
line.puts " end"
|
69
|
-
else
|
70
|
-
line.puts " " + object.capitalize.singularize + ".where('lower(" + attribute[0] + ") LIKE ?', '%' + @search.search + '%').each { |" + attribute[0] + "| @" + object.downcase.pluralize + ".any? { |f| f.id == " + attribute[0] + ".id } ? true : @" + object.downcase.pluralize + " << " + attribute[0] + " }"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
line.puts ' end'
|
74
|
-
line.puts ''
|
75
|
-
line.puts ' def clear'
|
76
|
-
line.puts ' @search = Search.find_by_search_id(1)'
|
77
|
-
line.puts ' @search.search = nil'
|
78
|
-
line.puts ' @search.save'
|
79
|
-
line.puts ' redirect_to ' + object.pluralize.downcase + '_path'
|
80
|
-
line.puts ' end'
|
81
|
-
line.puts ''
|
82
|
-
line.puts ' def check_for_search'
|
83
|
-
line.puts ' if Search.find_by_search_id(1) == nil'
|
84
|
-
line.puts ' @search = Search.new'
|
85
|
-
line.puts ' @search.search = nil'
|
86
|
-
line.puts ' @search.search_id = 1'
|
87
|
-
line.puts ' @search.save'
|
88
|
-
line.puts ' end'
|
89
|
-
line.puts ' end'
|
90
|
-
line.puts ''
|
91
|
-
line.puts ' def update_search'
|
92
|
-
line.puts ' respond_to do |format|'
|
93
|
-
line.puts ' if @search.update(search_params)'
|
94
|
-
line.puts ' format.html { redirect_to :back }'
|
95
|
-
line.puts ' format.json { render :show, status: :ok, location: @search }'
|
96
|
-
line.puts ' else'
|
97
|
-
line.puts ' format.html { render :edit }'
|
98
|
-
line.puts ' format.json { render json: @search.errors, status: :unprocessable_entity }'
|
99
|
-
line.puts ' end'
|
100
|
-
line.puts ' end'
|
101
|
-
line.puts ' end'
|
102
|
-
|
103
|
-
line.puts 'end'
|
104
|
-
end
|
105
|
-
Dir.chdir(root)
|
106
|
-
end
|
107
|
-
|
108
|
-
def write_search_controller
|
109
|
-
root = Dir.pwd
|
110
|
-
Dir.chdir(root + '/app/controllers')
|
111
|
-
File.open("searches_controller.rb", "a") do |line|
|
112
|
-
line.puts 'class SearchesController < ApplicationController'
|
113
|
-
line.puts ' before_action :set_search, only: [:show, :edit, :update, :destroy]'
|
114
|
-
line.puts ' before_action :include_search_module, only: [ :clear, :edit, :update ]'
|
115
|
-
line.puts ''
|
116
|
-
line.puts ' def clear'
|
117
|
-
line.puts ' clear'
|
118
|
-
line.puts ' end'
|
119
|
-
line.puts ''
|
120
|
-
line.puts ' def update'
|
121
|
-
line.puts ' update_search'
|
122
|
-
line.puts ' end'
|
123
|
-
line.puts ''
|
124
|
-
line.puts ' private'
|
125
|
-
line.puts ''
|
126
|
-
line.puts ' def set_search'
|
127
|
-
line.puts ' @search = Search.find_by_search_id(1)'
|
128
|
-
line.puts ' end'
|
129
|
-
line.puts ''
|
130
|
-
line.puts ' def include_search_module'
|
131
|
-
line.puts " $LOAD_PATH.unshift(File.dirname('../app/search'))"
|
132
|
-
line.puts ' extend SearchModule'
|
133
|
-
line.puts ' end'
|
134
|
-
line.puts ''
|
135
|
-
line.puts ' def search_params'
|
136
|
-
line.puts ' params.require(:search).permit(:search)'
|
137
|
-
line.puts ' end'
|
138
|
-
line.puts ''
|
139
|
-
line.puts 'end'
|
140
|
-
end
|
141
|
-
Dir.chdir(root)
|
142
|
-
end
|
143
|
-
|
144
|
-
def write_migration
|
145
|
-
require "fileutils"
|
146
|
-
require 'colorize'
|
147
|
-
root = Dir.pwd
|
148
|
-
Dir.chdir(root + '/db/migrate')
|
149
|
-
require 'date'
|
150
|
-
@time = DateTime.now.strftime('%Y%m%d%H%M%S')
|
151
|
-
if Dir[root + '/db/migrate/*_create_searches.rb'].count > 0
|
152
|
-
file = Dir[root + '/db/migrate/*_create_searches.rb'].first
|
153
|
-
puts 'Already Exists '.bold.green + file[38..100].bold
|
154
|
-
else
|
155
|
-
File.new @time + '_create_searches.rb', "w"
|
156
|
-
puts "Created ".green.bold + '/db/migrate/'.bold + @time.bold + '_create_searches.rb'.bold
|
157
|
-
File.open(@time + "_create_searches.rb", "a") do |line|
|
158
|
-
line.puts 'class CreateSearches < ActiveRecord::Migration'
|
159
|
-
line.puts ' def change'
|
160
|
-
line.puts ' create_table :searches do |t|'
|
161
|
-
line.puts ' t.string :search'
|
162
|
-
line.puts ' t.integer :search_id'
|
163
|
-
line.puts ' t.timestamps null: false'
|
164
|
-
line.puts ' end'
|
165
|
-
line.puts ' end'
|
166
|
-
line.puts 'end'
|
167
|
-
end
|
168
|
-
end
|
169
|
-
Dir.chdir(root)
|
170
|
-
end
|
171
|
-
|
172
|
-
def write_application_controller
|
173
|
-
require "fileutils"
|
174
|
-
root = Dir.pwd
|
175
|
-
Dir.chdir(root + '/app/controllers')
|
176
|
-
first_line = IO.readlines("application_controller.rb")[0]
|
177
|
-
other_lines = IO.readlines("application_controller.rb")[1..1000000000]
|
178
|
-
second_line = IO.readlines("application_controller.rb")[1]
|
179
|
-
|
180
|
-
if second_line.chomp == ' before_action :check_for_search'
|
181
|
-
puts 'Already Exists'.bold.green + ' /app/controllers/application_controller.rb'.bold
|
182
|
-
else
|
183
|
-
FileUtils::mkdir_p "migrate"
|
184
|
-
puts "Updated ".green.bold + '/app/controllers/application_controller.rb'.bold
|
185
|
-
File.open("application_controller.rb", "w") do |line|
|
186
|
-
line.puts first_line
|
187
|
-
line.puts ' before_action :check_for_search'
|
188
|
-
line.puts ''
|
189
|
-
line.puts ' def check_for_search'
|
190
|
-
line.puts " $LOAD_PATH.unshift(File.dirname('../app/search'))"
|
191
|
-
line.puts ' extend SearchModule'
|
192
|
-
line.puts ' check_for_search'
|
193
|
-
line.puts ' end'
|
194
|
-
line.puts ''
|
195
|
-
line.puts other_lines
|
196
|
-
end
|
197
|
-
end
|
198
|
-
Dir.chdir(root)
|
199
|
-
end
|
200
|
-
|
201
|
-
def write_search_model
|
202
|
-
require "fileutils"
|
203
|
-
root = Dir.pwd
|
204
|
-
Dir.chdir(root + '/app/models')
|
205
|
-
File.open("search.rb", "w") do |line|
|
206
|
-
line.puts 'class Search < ActiveRecord::Base'
|
207
|
-
line.puts 'end'
|
208
|
-
end
|
209
|
-
Dir.chdir(root)
|
210
|
-
end
|
211
|
-
|
212
|
-
def update_routes
|
213
|
-
require "fileutils"
|
214
|
-
root = Dir.pwd
|
215
|
-
Dir.chdir(root + '/config')
|
216
|
-
first_line = IO.readlines("routes.rb")[0]
|
217
|
-
other_lines = IO.readlines("routes.rb")[1..1000000000]
|
218
|
-
second_line = IO.readlines("routes.rb")[1]
|
219
|
-
if second_line.chomp == 'resources :searches do'
|
220
|
-
puts 'Already Exists'.bold.green + ' /config/routes.rb'.bold
|
221
|
-
else
|
222
|
-
File.open('routes.rb', 'w') do |line|
|
223
|
-
line.puts first_line
|
224
|
-
line.puts 'resources :searches do'
|
225
|
-
line.puts ' member do'
|
226
|
-
line.puts " get 'clear'"
|
227
|
-
line.puts ' end'
|
228
|
-
line.puts 'end'
|
229
|
-
line.puts other_lines
|
230
|
-
end
|
231
|
-
puts 'Updated '.bold.green + '/config/routes.rb'.bold
|
232
|
-
end
|
233
|
-
Dir.chdir(root)
|
234
|
-
end
|
235
|
-
|
236
|
-
def run
|
237
|
-
require 'colorize'
|
238
|
-
root = Dir.pwd
|
239
|
-
|
240
|
-
puts "Syntax: 'install OBJECT ATTRIBUTE:TYPE'".bold.on_red
|
241
|
-
command = gets.chomp
|
242
|
-
command = command.split(" ")
|
243
|
-
if command[0] == 'install'
|
244
|
-
puts ''
|
245
|
-
puts 'Creating Files...'.bold
|
246
|
-
object = command[1]
|
247
|
-
attributes = command[2..10000000]
|
248
|
-
end
|
249
|
-
|
250
|
-
SearchInstall.new.create_files
|
251
|
-
SearchInstall.new.write_search_controller
|
252
|
-
SearchInstall.new.write_search_model
|
253
|
-
SearchInstall.new.write_search_module(object, attributes)
|
254
|
-
SearchInstall.new.write_application_controller
|
255
|
-
SearchInstall.new.write_migration
|
256
|
-
SearchInstall.new.update_routes
|
257
|
-
|
258
|
-
puts 'Done'.bold
|
259
|
-
puts ''
|
260
|
-
|
261
|
-
|
262
|
-
end
|
263
|
-
|
264
|
-
end
|
265
|
-
|
266
|
-
|
267
|
-
class SearchInstallDevise
|
268
|
-
|
269
|
-
def create_files
|
270
|
-
require "colorize"
|
271
|
-
require "fileutils"
|
272
|
-
root = Dir.pwd
|
273
|
-
Dir.chdir(root + '/app')
|
274
|
-
if File.exists?('search')
|
275
|
-
puts 'Already Exists'.bold.green + ' /app/search'.bold
|
276
|
-
else
|
277
|
-
FileUtils::mkdir_p "search"
|
278
|
-
puts "Created ".green.bold + '/app/search'.bold
|
279
|
-
end
|
280
|
-
Dir.chdir(root + '/app/search')
|
281
|
-
if File.exists?('search_module.rb')
|
282
|
-
puts 'Already Exists'.bold.green + ' /app/search/search_module.rb'.bold
|
283
|
-
else
|
284
|
-
File.new "search_module.rb", "w"
|
285
|
-
puts "Created ".green.bold + '/app/search/search_module.rb'.bold
|
286
|
-
end
|
287
|
-
Dir.chdir(root + '/app/controllers')
|
288
|
-
if File.exists?('searches_controller.rb')
|
289
|
-
puts 'Already Exists'.bold.green + ' /app/controllers/searches_controller.rb'.bold
|
290
|
-
else
|
291
|
-
File.new "searches_controller.rb", "w"
|
292
|
-
puts "Created ".green.bold + '/app/controllers/searches_controller.rb'.bold
|
293
|
-
end
|
294
|
-
Dir.chdir(root + '/app/models')
|
295
|
-
if File.exists?('search.rb')
|
296
|
-
puts 'Already Exists'.bold.green + ' /app/models/search.rb'.bold
|
297
|
-
else
|
298
|
-
File.new "search.rb", "w"
|
299
|
-
puts 'Created '.green.bold + '/app/models/search.rb'.bold
|
300
|
-
end
|
301
|
-
Dir.chdir(root + '/db')
|
302
|
-
if File.exists?('migrate')
|
303
|
-
puts 'Already Exists'.bold.green + ' /db/migrate'.bold
|
304
|
-
else
|
305
|
-
FileUtils::mkdir_p "migrate"
|
306
|
-
puts "Created ".green.bold + '/db/migrate'.bold
|
307
|
-
end
|
308
|
-
Dir.chdir(root)
|
309
|
-
end
|
310
|
-
|
311
|
-
def write_search_module(object, attributes)
|
312
|
-
root = Dir.pwd
|
313
|
-
require 'active_support/inflector'
|
314
|
-
Dir.chdir(root + '/app/search')
|
315
|
-
File.open("search_module.rb", "a") do |line|
|
316
|
-
line.puts 'module SearchModule'
|
317
|
-
line.puts ' def search'
|
318
|
-
attri_one = attributes[0]
|
319
|
-
attribute = attri_one.split(':')
|
320
|
-
line.puts " @" + object.downcase.pluralize + " = " + object.capitalize.singularize + ".where('lower(" + attribute[0] + ") LIKE ?', '%' + @search.search.downcase + '%')"
|
321
|
-
attributes = attributes.reject { |attri| attri == attributes[0] }
|
322
|
-
attributes.each do |attri|
|
323
|
-
attribute = attri.split(':')
|
324
|
-
if attribute[1] == 'integer' || attribute[1] == 'decimal'
|
325
|
-
line.puts " " + object.capitalize.singularize + ".where('cast(" + attribute[0] + " AS VARCHAR) LIKE ?', '%' + @search.search + '%').each { |" + attribute[0] + "| @" + object.downcase.pluralize + ".any? { |f| f.id == " + attribute[0] + ".id } ? true : @" + object.downcase.pluralize + " << " + attribute[0] + " }"
|
326
|
-
elsif attribute[1] == 'boolean'
|
327
|
-
line.puts " if @search.search.downcase == 'true' || @search.search.downcase == 'tru' || @search.search.downcase == 'tr' || @search.search.downcase == 't'"
|
328
|
-
line.puts " " + object.capitalize.singularize + ".where(" + attribute[0] + ": true).each { |" + attribute[0] + "| @" + object.downcase.pluralize + ".any? { |f| f.id == " + attribute[0] + ".id } ? true : @" + object.downcase.pluralize + " << " + attribute[0] + " }"
|
329
|
-
line.puts " end"
|
330
|
-
line.puts " if @search.search.downcase == 'false' || @search.search.downcase == 'fals' || @search.search.downcase == 'fal' || @search.search.downcase == 'fa' || @search.search.downcase == 'f'"
|
331
|
-
line.puts " " + object.capitalize.singularize + ".where(" + attribute[0] + ": false).each { |" + attribute[0] + "| @" + object.downcase.pluralize + ".any? { |f| f.id == " + attribute[0] + ".id } ? true : @" + object.downcase.pluralize + " << " + attribute[0] + " }"
|
332
|
-
line.puts " end"
|
333
|
-
else
|
334
|
-
line.puts " " + object.capitalize.singularize + ".where('lower(" + attribute[0] + ") LIKE ?', '%' + @search.search + '%').each { |" + attribute[0] + "| @" + object.downcase.pluralize + ".any? { |f| f.id == " + attribute[0] + ".id } ? true : @" + object.downcase.pluralize + " << " + attribute[0] + " }"
|
335
|
-
end
|
336
|
-
end
|
337
|
-
line.puts ' end'
|
338
|
-
line.puts ''
|
339
|
-
line.puts ' def clear'
|
340
|
-
line.puts ' @search = Search.find_by(user_id: current_user.id)'
|
341
|
-
line.puts ' @search.search = nil'
|
342
|
-
line.puts ' @search.save'
|
343
|
-
line.puts ' redirect_to ' + object.pluralize.downcase + '_path'
|
344
|
-
line.puts ' end'
|
345
|
-
line.puts ''
|
346
|
-
line.puts ' def check_for_search'
|
347
|
-
line.puts ' if user_signed_in?'
|
348
|
-
line.puts ' if Search.find_by(user_id: current_user.id) == nil'
|
349
|
-
line.puts ' @search = Search.new'
|
350
|
-
line.puts ' @search.search = nil'
|
351
|
-
line.puts ' @search.user_id = current_user.id'
|
352
|
-
line.puts ' @search.save'
|
353
|
-
line.puts ' end'
|
354
|
-
line.puts ' end'
|
355
|
-
line.puts ' end'
|
356
|
-
line.puts ''
|
357
|
-
line.puts ' def update_search'
|
358
|
-
line.puts ' respond_to do |format|'
|
359
|
-
line.puts ' if @search.update(search_params)'
|
360
|
-
line.puts ' format.html { redirect_to :back }'
|
361
|
-
line.puts ' format.json { render :show, status: :ok, location: @search }'
|
362
|
-
line.puts ' else'
|
363
|
-
line.puts ' format.html { render :edit }'
|
364
|
-
line.puts ' format.json { render json: @search.errors, status: :unprocessable_entity }'
|
365
|
-
line.puts ' end'
|
366
|
-
line.puts ' end'
|
367
|
-
line.puts ' end'
|
368
|
-
|
369
|
-
line.puts 'end'
|
370
|
-
end
|
371
|
-
Dir.chdir(root)
|
372
|
-
end
|
373
|
-
|
374
|
-
def write_search_controller
|
375
|
-
root = Dir.pwd
|
376
|
-
Dir.chdir(root + '/app/controllers')
|
377
|
-
File.open("searches_controller.rb", "a") do |line|
|
378
|
-
line.puts 'class SearchesController < ApplicationController'
|
379
|
-
line.puts ' before_action :set_search, only: [:show, :edit, :update, :destroy]'
|
380
|
-
line.puts ' before_action :include_search_module, only: [ :clear, :edit, :update ]'
|
381
|
-
line.puts ''
|
382
|
-
line.puts ' def clear'
|
383
|
-
line.puts ' clear'
|
384
|
-
line.puts ' end'
|
385
|
-
line.puts ''
|
386
|
-
line.puts ' def update'
|
387
|
-
line.puts ' update_search'
|
388
|
-
line.puts ' end'
|
389
|
-
line.puts ''
|
390
|
-
line.puts ' private'
|
391
|
-
line.puts ''
|
392
|
-
line.puts ' def set_search'
|
393
|
-
line.puts ' @search = Search.find_by(user_id: current_user.id)'
|
394
|
-
line.puts ' end'
|
395
|
-
line.puts ''
|
396
|
-
line.puts ' def include_search_module'
|
397
|
-
line.puts " $LOAD_PATH.unshift(File.dirname('../app/search'))"
|
398
|
-
line.puts ' extend SearchModule'
|
399
|
-
line.puts ' end'
|
400
|
-
line.puts ''
|
401
|
-
line.puts ' def search_params'
|
402
|
-
line.puts ' params.require(:search).permit(:search, :user_id)'
|
403
|
-
line.puts ' end'
|
404
|
-
line.puts ''
|
405
|
-
line.puts 'end'
|
406
|
-
end
|
407
|
-
Dir.chdir(root)
|
408
|
-
end
|
409
|
-
|
410
|
-
def write_migration
|
411
|
-
require "fileutils"
|
412
|
-
require 'colorize'
|
413
|
-
root = Dir.pwd
|
414
|
-
Dir.chdir(root + '/db/migrate')
|
415
|
-
require 'date'
|
416
|
-
@time = DateTime.now.strftime('%Y%m%d%H%M%S')
|
417
|
-
if Dir[root + '/db/migrate/*_create_searches.rb'].count > 0
|
418
|
-
file = Dir[root + '/db/migrate/*_create_searches.rb'].first
|
419
|
-
puts 'Already Exists '.bold.green + file[38..100].bold
|
420
|
-
else
|
421
|
-
File.new @time + '_create_searches.rb', "w"
|
422
|
-
puts "Created ".green.bold + '/db/migrate/'.bold + @time.bold + '_create_searches.rb'.bold
|
423
|
-
File.open(@time + "_create_searches.rb", "a") do |line|
|
424
|
-
line.puts 'class CreateSearches < ActiveRecord::Migration'
|
425
|
-
line.puts ' def change'
|
426
|
-
line.puts ' create_table :searches do |t|'
|
427
|
-
line.puts ' t.string :search'
|
428
|
-
line.puts ' t.integer :user_id'
|
429
|
-
line.puts ' t.timestamps null: false'
|
430
|
-
line.puts ' end'
|
431
|
-
line.puts ' end'
|
432
|
-
line.puts 'end'
|
433
|
-
end
|
434
|
-
end
|
435
|
-
Dir.chdir(root)
|
436
|
-
end
|
437
|
-
|
438
|
-
def write_application_controller
|
439
|
-
require "fileutils"
|
440
|
-
root = Dir.pwd
|
441
|
-
Dir.chdir(root + '/app/controllers')
|
442
|
-
first_line = IO.readlines("application_controller.rb")[0]
|
443
|
-
other_lines = IO.readlines("application_controller.rb")[1..1000000000]
|
444
|
-
second_line = IO.readlines("application_controller.rb")[1]
|
445
|
-
|
446
|
-
if second_line.chomp == ' before_action :check_for_search'
|
447
|
-
puts 'Already Exists'.bold.green + ' /app/controllers/application_controller.rb'.bold
|
448
|
-
else
|
449
|
-
FileUtils::mkdir_p "migrate"
|
450
|
-
puts "Updated ".green.bold + '/app/controllers/application_controller.rb'.bold
|
451
|
-
File.open("application_controller.rb", "w") do |line|
|
452
|
-
line.puts first_line
|
453
|
-
line.puts ' before_action :check_for_search'
|
454
|
-
line.puts ''
|
455
|
-
line.puts ' def check_for_search'
|
456
|
-
line.puts " $LOAD_PATH.unshift(File.dirname('../app/search'))"
|
457
|
-
line.puts ' extend SearchModule'
|
458
|
-
line.puts ' check_for_search'
|
459
|
-
line.puts ' end'
|
460
|
-
line.puts ''
|
461
|
-
line.puts other_lines
|
462
|
-
end
|
463
|
-
end
|
464
|
-
Dir.chdir(root)
|
465
|
-
end
|
466
|
-
|
467
|
-
def write_search_model
|
468
|
-
require "fileutils"
|
469
|
-
root = Dir.pwd
|
470
|
-
Dir.chdir(root + '/app/models')
|
471
|
-
File.open("search.rb", "w") do |line|
|
472
|
-
line.puts 'class Search < ActiveRecord::Base'
|
473
|
-
line.puts 'end'
|
474
|
-
end
|
475
|
-
Dir.chdir(root)
|
476
|
-
end
|
477
|
-
|
478
|
-
def update_routes
|
479
|
-
require "fileutils"
|
480
|
-
root = Dir.pwd
|
481
|
-
Dir.chdir(root + '/config')
|
482
|
-
first_line = IO.readlines("routes.rb")[0]
|
483
|
-
other_lines = IO.readlines("routes.rb")[1..1000000000]
|
484
|
-
second_line = IO.readlines("routes.rb")[1]
|
485
|
-
if second_line.chomp == 'resources :searches do'
|
486
|
-
puts 'Already Exists'.bold.green + ' /config/routes.rb'.bold
|
487
|
-
else
|
488
|
-
File.open('routes.rb', 'w') do |line|
|
489
|
-
line.puts first_line
|
490
|
-
line.puts 'resources :searches do'
|
491
|
-
line.puts ' member do'
|
492
|
-
line.puts " get 'clear'"
|
493
|
-
line.puts ' end'
|
494
|
-
line.puts 'end'
|
495
|
-
line.puts other_lines
|
496
|
-
end
|
497
|
-
puts 'Updated '.bold.green + '/config/routes.rb'.bold
|
498
|
-
end
|
499
|
-
Dir.chdir(root)
|
500
|
-
end
|
501
|
-
|
502
|
-
def run
|
503
|
-
require 'colorize'
|
504
|
-
root = Dir.pwd
|
505
|
-
|
506
|
-
puts "Syntax: 'install OBJECT ATTRIBUTE:TYPE'".bold.on_red
|
507
|
-
command = gets.chomp
|
508
|
-
command = command.split(" ")
|
509
|
-
if command[0] == 'install'
|
510
|
-
puts ''
|
511
|
-
puts 'Creating Files...'.bold
|
512
|
-
object = command[1]
|
513
|
-
attributes = command[2..10000000]
|
514
|
-
end
|
515
|
-
|
516
|
-
SearchInstallDevise.new.create_files
|
517
|
-
SearchInstallDevise.new.write_search_controller
|
518
|
-
SearchInstallDevise.new.write_search_model
|
519
|
-
SearchInstallDevise.new.write_search_module(object, attributes)
|
520
|
-
SearchInstallDevise.new.write_application_controller
|
521
|
-
SearchInstallDevise.new.write_migration
|
522
|
-
SearchInstallDevise.new.update_routes
|
523
|
-
|
524
|
-
puts 'Done'.bold
|
525
|
-
puts ''
|
526
|
-
|
527
|
-
|
528
|
-
end
|
529
|
-
|
530
|
-
end
|
3
|
+
require "active_support/all"
|
4
|
+
require "active_record"
|
5
|
+
require "query-ruby"
|
6
|
+
require "zeitwerk"
|
7
|
+
require "chronic"
|
531
8
|
|
9
|
+
loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
|
10
|
+
loader.ignore("#{__dir__}/search_rails.rb")
|
11
|
+
loader.setup
|
532
12
|
|
13
|
+
class Object
|
14
|
+
alias is_an? is_a?
|
533
15
|
end
|
data/package-lock.json
ADDED
data/package.json
ADDED
data/search_rails.gemspec
CHANGED
@@ -1,29 +1,23 @@
|
|
1
|
-
#
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'search_rails/version'
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "search_rails"
|
5
|
+
s.version = File.read("VERSION").strip
|
6
|
+
s.summary = "a powerful search for rails"
|
7
|
+
s.description = s.summary
|
8
|
+
s.authors = ["Dorian Marié"]
|
9
|
+
s.email = "dorian@dorianmarie.com"
|
10
|
+
s.files = `git ls-files`.lines.map(&:strip)
|
11
|
+
s.require_paths = ["lib"]
|
12
|
+
s.homepage = "https://github.com/dorianmariecom/search_rails"
|
13
|
+
s.license = "MIT"
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
s.add_dependency "rails"
|
16
|
+
s.add_dependency "query-ruby"
|
17
|
+
s.add_dependency "zeitwerk"
|
18
|
+
s.add_dependency "chronic"
|
16
19
|
|
20
|
+
s.metadata["rubygems_mfa_required"] = "true"
|
17
21
|
|
18
|
-
|
19
|
-
f.match(%r{^(test|spec|features)/})
|
20
|
-
end
|
21
|
-
spec.bindir = "bin"
|
22
|
-
spec.executables = ["search:install", "search:install:devise"]
|
23
|
-
spec.require_paths = ["lib"]
|
24
|
-
|
25
|
-
spec.add_development_dependency "bundler", "~> 1.13"
|
26
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
-
spec.add_development_dependency "colorize"
|
22
|
+
s.required_ruby_version = ">= 3.0"
|
29
23
|
end
|