rails_db_objects 0.0.4 → 1.0.1

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
- SHA1:
3
- metadata.gz: afc01e0387360fcb96fba128c134264785d3aa24
4
- data.tar.gz: d6939321cb8ad14aad0542f9b2850a513803d438
2
+ SHA256:
3
+ metadata.gz: 143af972ad8ea77cc95795ebc4a66a25ca5ba9304274b24fa0d14c242777271e
4
+ data.tar.gz: af6b3a46babeec69fec292539f06b47a587358ecb73fed09624ce10ba8d158e2
5
5
  SHA512:
6
- metadata.gz: b798277b3917e245c816b71e24f0be801391a4b68f1fa5875d0c0ee692eeb6ef09035c41d7ca29642c6501d66aba78a7dea00968c6c7deee61fe7defe6c03c39
7
- data.tar.gz: 5b7dd89cf92e2e3a74e696f2f85eba662df826806798b56ef5d87b6ef077d4b7d9430c9ce7f3fbfe1ec6e086cda6f49ad74d705bc8efb214df9541ab936b4793
6
+ metadata.gz: a2766067a2980382e9055ab4c7caf5d73da8741f074037d23cd9cb6bcf31c1af87a31c6d6e1ae2c919b2b26ed44b83459e7ffe06370823f17ad45907d24b73a5
7
+ data.tar.gz: 0574b8ec3120c5b8d942be92b66ee9f952fd1e63a974d5a35fd55f9415f4114a41504c7fa50559f22b9502d25e8e9657e370d2143806c239f48855606ca74022
data/Rakefile CHANGED
@@ -14,11 +14,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
-
18
-
19
-
20
-
21
-
22
17
  Bundler::GemHelper.install_tasks
23
18
 
24
19
  require 'rake/testtask'
@@ -30,5 +25,4 @@ Rake::TestTask.new(:test) do |t|
30
25
  t.verbose = false
31
26
  end
32
27
 
33
-
34
28
  task default: :test
@@ -1,227 +1,318 @@
1
- class RailsDbObjects::DbObjectsCreator
2
- attr_reader :objects
1
+ module RailsDbObjects
2
+ class DbObjectsCreator
3
+ attr_reader :objects
3
4
 
4
- def initialize
5
- @objects = {}
6
- end
5
+ def initialize
6
+ @objects = {}
7
+ end
7
8
 
8
- def register_files files
9
- files.each do |file|
10
- object_name = File.basename(file, File.extname(file))
11
- object_type = File.dirname(file.to_s).to_s.split('/').last.upcase
12
-
13
- @objects[object_type] ||= {}
14
-
15
- content = File.read(file)
16
- content_lines = content.split("\n")
17
-
18
- # Reject the commented lines from the file
19
- sql_content = content_lines.reject{ |x| x.strip =~ /^--/ || x.strip =~ /^#/ }.join("\n")
20
-
21
- file_obj = {
22
- path: file,
23
- sql_content: sql_content,
24
- status: :none,
25
- requires: [],
26
- silent: false,
27
- keep: false,
28
- deleted: false,
29
- dbschema: Rails.configuration.rails_db_objects[:objects_dbschema],
30
- dropsql: [],
31
- createsql: [],
32
- vanilla: false,
33
- condition: []
34
- }
35
-
36
- # Detect directives in commentary
37
- directives = content_lines.select{ |x| x.strip =~ /^--/ || x.strip =~ /^#/ }.map(&:strip).map{ |x|
38
- x =~ /^--/ ? x[2..-1] : x[1..-1]
39
- }.select{|x| x =~ /^!/ }
40
-
41
- #puts "directives: #{directives.inspect}"
42
- directives.each do |directive|
43
- if directive =~ /^!require /
44
- file_obj[:requires] += directive.split(" ")[1..-1]
45
- end
46
- if directive =~ /^!vanilla/
47
- file_obj[:vanilla] = true
48
- end
49
- if directive =~ /^!deleted/
50
- file_obj[:skip_post] = true
51
- end
52
- if directive =~ /^!silent/
53
- file_obj[:silent] = true
54
- end
55
- if directive =~ /^!keep/
56
- file_obj[:skip_pre] = true
57
- end
58
- if directive =~ /^!schema/
59
- file_obj[:dbschema] = directive.split(" ")[1..-1]
60
- end
61
- if directive =~ /^!condition /
62
- file_obj[:condition] << directive.split(" ")[1..-1].join(" ")
63
- end
64
- if directive =~ /^!dropsql /
65
- file_obj[:dropsql] << directive.split(" ")[1..-1].join(" ")
66
- end
67
- if directive =~ /^!createsql /
68
- file_obj[:createsql] << directive.split(" ")[1..-1].join(" ")
69
- end
70
- end
9
+ def register_files(files)
10
+ files.each do |file|
11
+ object_name = File.basename(file, File.extname(file))
12
+ object_type = File.dirname(file.to_s).to_s.split('/').last.upcase
71
13
 
72
- @objects[object_type][object_name] = file_obj
73
- end
74
- end
14
+ @objects[object_type] ||= {}
15
+
16
+ content = File.read(file)
17
+ content_lines = content.split("\n")
18
+
19
+ # Reject the commented lines from the file
20
+ sql_content = content_lines.reject { |x| x.strip =~ /^--/ || x.strip =~ /^#/ }.join("\n")
21
+
22
+ file_obj = {
23
+ name: object_name,
24
+ type: object_type,
25
+ debug: false,
26
+ directives: [],
27
+ path: file,
28
+ sql_content: sql_content,
29
+ status: :none,
30
+ requires: [],
31
+ silent: false,
32
+ keep: false,
33
+ nodrop: false,
34
+ deleted: false,
35
+ nocreate: false,
36
+ dbschema: Rails.configuration.rails_db_objects[:objects_dbschema],
37
+ dropsql: [],
38
+ createsql: [],
39
+ vanilla: false,
40
+ condition: [],
41
+ dropconditionruby: [],
42
+ createconditionruby: [],
43
+ beforedropruby: [],
44
+ beforedropsql: [],
45
+ afterdropruby: [],
46
+ afterdropsql: [],
47
+ beforecreateruby: [],
48
+ beforecreatesql: [],
49
+ aftercreateruby: [],
50
+ aftercreatesql: []
51
+ }
52
+
53
+ # Detect directives in commentary
54
+ directives = extract_from_comments(content_lines)
75
55
 
76
- def drop_objects
77
- reset_objects_status!
78
- @objects.keys.each do |object_type|
79
- @objects[object_type].each do |name, object|
80
- drop_object(object_type, name, object) unless object[:skip_pre]
56
+ # puts "directives: #{directives.inspect}"
57
+ directives.each { |directive| prepare_directive(file_obj, directive) }
58
+
59
+ @objects[object_type][object_name] = file_obj
81
60
  end
82
61
  end
83
- end
84
62
 
85
- def create_objects
86
- reset_objects_status!
87
- @objects.keys.each do |object_type|
88
- @objects[object_type].each do |name, object|
89
- create_object(object_type, name, object) unless object[:skip_post]
63
+ def drop_objects
64
+ reset_objects_status!
65
+ @objects.keys.each do |object_type|
66
+ @objects[object_type].each do |_name, object|
67
+ drop_object(object)
68
+ end
90
69
  end
91
70
  end
92
- end
93
71
 
94
- private
95
- def reset_objects_status!
96
- @objects.keys.each do |object_type|
97
- @objects[object_type].each do |name, object|
98
- object[:status] = :none
72
+ def create_objects
73
+ reset_objects_status!
74
+ @objects.keys.each do |object_type|
75
+ @objects[object_type].each do |_name, object|
76
+ create_object(object)
77
+ end
99
78
  end
100
79
  end
101
- end
102
80
 
81
+ private
82
+
83
+ def full(name)
84
+ prefix = @dbschema.blank? ? '' : "#{@dbschema}."
85
+ "#{prefix}#{wrap_name(name)}"
86
+ end
87
+
88
+ def wrap_name(name)
89
+ adapter_name = ActiveRecord::Base.connection.adapter_name
103
90
 
104
- def drop_object object_type, name, object
105
- return if object[:status] == :loaded
91
+ case adapter_name
92
+ when 'PostgreSQL'
93
+ "\"#{name}\""
94
+ when 'MySQL'
95
+ "`#{name}`"
96
+ when 'SQLServer'
97
+ "[#{name}]"
98
+ end
99
+ end
106
100
 
107
- if object[:status] == :inprogress
108
- raise "Error: Circular file reference! (#{object_type} #{name})"
101
+ def extract_from_comments(content_lines)
102
+ dir_lines = content_lines.select { |x| x.strip =~ /^--/ || x.strip =~ /^#/ }.map(&:strip)
103
+ dir_lines.map { |x| /^--/.match?(x) ? x[2..-1] : x[1..-1] }.select { |x| x =~ /^!/ }
109
104
  end
110
105
 
111
- object[:requires].each do |requirement|
112
- requires = requirement.split('/', 2)
113
- required_object = requires.last
114
- required_type = requires.first.upcase if requires.length==2
115
- required_type ||= object_type
116
- drop_object required_type, required_object, @objects[required_type.upcase][required_object]
106
+ # rubocop:disable Metrics/AbcSize
107
+ def prepare_directive(file_obj, directive)
108
+ file_obj[:debug] = /^!debug/.match?(directive) unless file_obj[:debug]
109
+ file_obj[:directives] << directive
110
+ file_obj[:requires] += directive.split(' ')[1..-1] if /^!require /.match?(directive)
111
+ file_obj[:vanilla] = /^!vanilla/.match?(directive) unless file_obj[:vanilla]
112
+ file_obj[:nocreate] = file_obj[:deleted] = /^!deleted/.match?(directive) unless file_obj[:deleted]
113
+ file_obj[:silent] = /^!silent/.match?(directive) unless file_obj[:silent]
114
+ file_obj[:nodrop] = file_obj[:keep] = /^!keep/.match?(directive) unless file_obj[:keep]
115
+ file_obj[:dbschema] = directive.split(' ')[1..-1] if /^!schema/.match?(directive)
116
+ file_obj[:dropconditionruby] << directive.split(' ')[1..-1].join(' ') if /^!dropconditionruby /.match?(directive)
117
+ file_obj[:createconditionruby] << directive.split(' ')[1..-1].join(' ') if /^!createconditionruby /.match?(directive)
118
+ file_obj[:condition] << directive.split(' ')[1..-1].join(' ') if /^!condition /.match?(directive)
119
+ file_obj[:beforedropsql] << directive.split(' ')[1..-1].join(' ') if /^!beforedropsql /.match?(directive)
120
+ file_obj[:dropsql] << directive.split(' ')[1..-1].join(' ') if /^!dropsql /.match?(directive)
121
+ file_obj[:afterdropsql] << directive.split(' ')[1..-1].join(' ') if /^!afterdropsql /.match?(directive)
122
+ file_obj[:beforecreatesql] << directive.split(' ')[1..-1].join(' ') if /^!beforecreatesql /.match?(directive)
123
+ file_obj[:createsql] << directive.split(' ')[1..-1].join(' ') if /^!createsql /.match?(directive)
124
+ file_obj[:aftercreatesql] << directive.split(' ')[1..-1].join(' ') if /^!aftercreatesql /.match?(directive)
117
125
  end
126
+ # rubocop:enable Metrics/AbcSize
118
127
 
119
- dbschema = (object[:dbschema] || []).clone
120
- full_name = [dbschema, "[#{name}]"].flatten.reject(&:blank?).compact.join('.')
128
+ def reset_objects_status!
129
+ @objects.keys.each do |object_type|
130
+ @objects[object_type].each do |_name, object|
131
+ object[:status] = :none
132
+ end
133
+ end
134
+ end
121
135
 
122
- if object[:vanilla]
123
- sql = object[:sql_content]
124
- else
125
- unless object[:dropsql].compact.empty?
126
- sql = object[:dropsql].compact.join("\n")
127
- else
128
- sql = "DROP #{object_type} #{full_name}"
136
+ def conditional_ruby(condition, object)
137
+ interpolated_command = object.instance_eval('"' + condition.gsub(/\"/, '\"') + '"')
138
+ condition = object.instance_eval(interpolated_command)
139
+ if object[:debug]
140
+ puts '=' * 80
141
+ puts "interpolated_command: #{interpolated_command}"
142
+ puts '=' * 80
143
+ puts "condition: #{condition.inspect}"
144
+ puts '=' * 80
129
145
  end
146
+ condition ? true : false
130
147
  end
131
148
 
132
- begin
133
- unless object[:condition].compact.empty?
134
- condition = !ActiveRecord::Base.connection.select_rows(object[:condition].join("\n")).empty?
135
- unless condition
136
- puts "CONDITION NOT MET FOR #{object_type} #{full_name}"
149
+ def interpolate_sql(sql, object)
150
+ object.instance_eval('"' + sql.gsub(/\"/, '\"') + '"')
151
+ end
152
+
153
+ # rubocop:disable Metrics/AbcSize
154
+ def drop_object(object)
155
+ return if object[:nodrop]
156
+
157
+ return if object[:status] == :loaded
158
+
159
+ object_type = object[:type]
160
+ name = object[:name]
161
+ @dbschema = (object[:dbschema] || []).clone
162
+
163
+ raise "Error: Circular file reference! (#{object_type} #{name})" if object[:status] == :inprogress
164
+
165
+ full_name = full(name)
166
+
167
+ if object[:dropconditionruby].compact.any?
168
+ condition = conditional_ruby(object[:dropconditionruby].join("\n"), object)
169
+ if condition
170
+ puts "RUBY CONDITION MET FOR #{object_type} #{full_name} #{condition}"
171
+ else
172
+ puts "RUBY CONDITION NOT MET FOR #{object_type} #{full_name} #{condition}"
137
173
  return
174
+ end
175
+ elsif object[:condition].compact.any?
176
+ condition = !ActiveRecord::Base.connection.select_rows(object[:condition].join("\n")).empty?
177
+ if condition
178
+ puts "SQL CONDITION MET FOR #{object_type} #{full_name}"
138
179
  else
139
- puts "CONDITION MET FOR #{object_type} #{full_name}"
180
+ puts "SQL CONDITION NOT MET FOR #{object_type} #{full_name}"
181
+ return
140
182
  end
141
183
  end
142
- ActiveRecord::Base.connection.execute(sql)
143
- puts "#{sql}... OK"
144
- rescue => e
145
- unless object[:silent]
146
- puts "#"*80
147
- puts "#{e.message}"
148
- #puts "#"*80
149
- #puts "#{e.backtrace}"
150
- puts "#"*80
151
- puts "WARNING: #{sql}... ERROR"
152
- puts "#"*80
153
- # else
154
- # puts "WARNING: #{sql}... SILENT"
184
+
185
+ if object[:debug]
186
+ puts '=' * 80
187
+ puts "DROP OBJECT #{name} / #{object[:path]}"
188
+ puts '=' * 80
189
+ puts object.to_json
190
+ puts '=' * 80
155
191
  end
156
- end
157
192
 
158
- object[:status] = :loaded
159
- end
193
+ object[:requires].each do |requirement|
194
+ requires = requirement.split('/', 2)
195
+ required_object = requires.last
196
+ required_type = requires.first.upcase if requires.length == 2
197
+ required_type ||= object_type
198
+ drop_object @objects[required_type.upcase][required_object]
199
+ end
160
200
 
161
- def create_object object_type, name, object
162
- # skip empty sql content
163
- if object[:sql_content].strip.blank?
164
- puts "#{object_type} #{name} EMPTY... SKIPPING"
165
- return
166
- end
201
+ sql = if object[:dropsql].compact.empty? && !object[:vanilla]
202
+ "DROP #{object_type} #{full_name};"
203
+ else
204
+ interpolate_sql(object[:dropsql].compact.join(";\n"), object)
205
+ end
167
206
 
168
- # object already loaded.
169
- return if object[:status] == :loaded
207
+ begin
208
+ conditional_ruby(object[:beforedropruby].join("\n"), object) unless object[:beforedropruby].empty?
209
+ ActiveRecord::Base.connection.exec_query(object[:beforedropsql].join("\n")) unless object[:beforedropsql].empty?
210
+ ActiveRecord::Base.connection.exec_query(sql)
211
+ ActiveRecord::Base.connection.exec_query(object[:afterdropsql].join("\n")) unless object[:afterdropsql].empty?
212
+ puts "DROP #{object_type} #{full_name}... OK"
213
+ conditional_ruby(object[:afterdropruby].join("\n"), object) unless object[:afterdropruby].empty?
214
+ rescue StandardError => e
215
+ unless object[:debug]
216
+ puts '#' * 80
217
+ puts e.message.to_s
218
+ puts "-"*80
219
+ #puts "#{e.backtrace}"
220
+ #puts '-' * 80
221
+ puts "WARNING: >>#{sql}<<... ERROR"
222
+ puts '#' * 80
223
+ end
224
+ end
170
225
 
171
- if object[:status] == :inprogress
172
- raise "Error: Circular file reference! (#{object_type} #{name})"
226
+ object[:status] = :loaded
173
227
  end
174
228
 
175
- object[:status] = :inprogress
229
+ def create_object(object)
230
+ return if object[:nocreate]
176
231
 
177
- object[:requires].each do |requirement|
178
- requires = requirement.split('/', 2)
179
- required_object = requires.last
180
- required_type = requires.first.upcase if requires.length==2
181
- required_type ||= object_type
182
- create_object required_type, required_object, @objects[required_type.upcase][required_object]
183
- end
232
+ return if object[:status] == :loaded
184
233
 
185
- dbschema = (object[:dbschema] || []).clone
186
- full_name = [dbschema, "[#{name}]"].flatten.reject(&:blank?).compact.join('.')
234
+ object_type = object[:type]
235
+ name = object[:name]
187
236
 
188
- if object[:vanilla]
189
- sql = object[:sql_content]
190
- else
191
- unless object[:createsql].compact.empty?
192
- sql = object[:createsql].compact.join("\n")
193
- else
194
- sql = "CREATE #{object_type} #{full_name}\n#{object[:sql_content]}"
195
- end
196
- end
237
+ raise "Error: Circular file reference! (#{object_type} #{name})" if object[:status] == :inprogress
197
238
 
198
- begin
199
- unless object[:condition].compact.empty?
200
- condition = ActiveRecord::Base.connection.select_rows(object[:condition].join("\n")).empty?
201
- unless condition
202
- puts "CONDITION NOT MET FOR #{object_type} #{full_name}"
239
+ object[:status] = :inprogress
240
+ @dbschema = (object[:dbschema] || []).clone
241
+
242
+ full_name = full(name)
243
+
244
+ if object[:createconditionruby].compact.any?
245
+ condition = conditional_ruby(object[:createconditionruby].join("\n"), object)
246
+ if condition
247
+ puts "RUBY CONDITION MET FOR #{object_type} #{full_name} / #{condition}"
248
+ else
249
+ puts "RUBY CONDITION NOT MET FOR #{object_type} #{full_name}"
203
250
  return
251
+ end
252
+ elsif object[:condition].compact.any?
253
+ condition = ActiveRecord::Base.connection.select_rows(object[:condition].join("\n")).empty?
254
+ if condition
255
+ puts "CONDITION MET FOR #{object_type} #{full_name}"
204
256
  else
205
- puts "CONDITION MET FOR #{object_type} #{full_name}"
257
+ puts "CONDITION NOT MET FOR #{object_type} #{full_name}"
258
+ return
206
259
  end
207
260
  end
208
- ActiveRecord::Base.connection.execute("#{sql}")
209
- puts "CREATE #{object_type} #{full_name}... OK"
210
- rescue => e
211
- unless object[:silent]
212
- puts "#"*80
213
- puts "#{e.message}"
214
- #puts "#"*80
215
- #puts "#{e.backtrace}"
216
- puts "#"*80
217
- puts "WARNING: CREATE #{object_type} #{full_name}... ERROR"
218
- puts "#"*80
219
- # else
220
- # puts "WARNING: CREATE #{object_type} #{full_name}... SILENT"
261
+
262
+ if object[:debug]
263
+ puts '=' * 80
264
+ puts "CREATE OBJECT #{name} / #{object[:path]}"
265
+ puts '=' * 80
266
+ puts object.to_json
267
+ puts '=' * 80
268
+ end
269
+ # skip empty sql content
270
+ if object[:sql_content].strip.blank?
271
+ puts "#{object_type} #{name} EMPTY... SKIPPING"
272
+ return
221
273
  end
274
+
275
+ create_dependencies(object, object_type)
276
+
277
+ sql = if object[:vanilla]
278
+ interpolate_sql(object[:sql_content], object)
279
+ elsif object[:createsql].compact.empty?
280
+ "CREATE #{object_type} #{full_name}\n#{object[:sql_content]}"
281
+ else
282
+ interpolate_sql(object[:createsql].compact.join(";\n"), object)
283
+ end
284
+
285
+ begin
286
+ conditional_ruby(object[:beforecreateruby].join("\n"), object) unless object[:beforecreateruby].empty?
287
+ ActiveRecord::Base.connection.exec_query(object[:beforecreatesql].join("\n")) unless object[:beforecreatesql].empty?
288
+ ActiveRecord::Base.connection.exec_query(sql.to_s)
289
+ ActiveRecord::Base.connection.exec_query(object[:aftercreatesql].join("\n")) unless object[:aftercreatesql].empty?
290
+ conditional_ruby(object[:aftercreateruby].join("\n"), object) unless object[:aftercreateruby].empty?
291
+ puts "CREATE #{object_type} #{full_name}... OK"
292
+ rescue StandardError => e
293
+ unless object[:silent]
294
+ puts '#' * 80
295
+ puts e.message.to_s
296
+ puts '-' * 80
297
+ puts sql.to_s
298
+ puts '-' * 80
299
+ puts "WARNING: CREATE #{object_type} #{full_name}... ERROR"
300
+ puts '#' * 80
301
+ end
302
+ end
303
+
304
+ object[:status] = :loaded
222
305
  end
306
+ # rubocop:enable Metrics/AbcSize
223
307
 
224
- object[:status] = :loaded
308
+ def create_dependencies(object, object_type)
309
+ object[:requires].each do |requirement|
310
+ requires = requirement.split('/', 2)
311
+ required_object = requires.last
312
+ required_type = requires.first.upcase if requires.length == 2
313
+ required_type ||= object_type
314
+ create_object(@objects[required_type.upcase][required_object])
315
+ end
316
+ end
225
317
  end
226
-
227
318
  end
@@ -3,13 +3,13 @@ class Railtie < Rails::Railtie
3
3
 
4
4
  config.rails_db_objects = ActiveSupport::OrderedHash.new
5
5
 
6
- initializer "rails_db_objects.initialize" do |app|
7
- app.config.rails_db_objects[:objects_path] = %w( db/objects/**/ )
8
- app.config.rails_db_objects[:objects_ext] = "*.sql"
6
+ initializer 'rails_db_objects.initialize' do |app|
7
+ app.config.rails_db_objects[:objects_path] = %w[db/objects/**/]
8
+ app.config.rails_db_objects[:objects_ext] = '*.sql'
9
9
  app.config.rails_db_objects[:objects_dbschema] = ['dbo']
10
10
  end
11
11
 
12
12
  rake_tasks do
13
- load "tasks/rails_db_objects_tasks.rake"
13
+ load 'tasks/rails_db_objects_tasks.rake'
14
14
  end
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module RailsDbObjects
2
- VERSION = "0.0.4"
2
+ VERSION = '1.0.1'.freeze
3
3
  end
@@ -1,28 +1,27 @@
1
1
  namespace :db do
2
-
3
- desc "Generate all the database objects of the current project"
4
- task :create_objects => :environment do
2
+ desc 'Generate all the database objects of the current project'
3
+ task create_objects: :environment do
5
4
  creator = RailsDbObjects::DbObjectsCreator.new
6
5
 
7
- objects_path, objects_ext = Rails.configuration.rails_db_objects[:objects_path], Rails.configuration.rails_db_objects[:objects_ext]
6
+ objects_path = Rails.configuration.rails_db_objects[:objects_path]
7
+ objects_ext = Rails.configuration.rails_db_objects[:objects_ext]
8
8
 
9
9
  objects_path.each do |path|
10
- creator.register_files Dir[File.join(path, objects_ext)].map {|x|
11
- File.expand_path(x)
12
- }
10
+ creator.register_files(Dir[File.join(path, objects_ext)].map { |x| File.expand_path(x) })
13
11
  end
14
12
 
15
13
  creator.create_objects
16
14
  end
17
15
 
18
- desc "Drop all the database objects of the current project"
19
- task :drop_objects => :environment do
16
+ desc 'Drop all the database objects of the current project'
17
+ task drop_objects: :environment do
20
18
  creator = RailsDbObjects::DbObjectsCreator.new
21
19
 
22
- objects_path, objects_ext = Rails.configuration.rails_db_objects[:objects_path], Rails.configuration.rails_db_objects[:objects_ext]
20
+ objects_path = Rails.configuration.rails_db_objects[:objects_path]
21
+ objects_ext = Rails.configuration.rails_db_objects[:objects_ext]
23
22
 
24
23
  objects_path.each do |path|
25
- creator.register_files Dir[File.join(path, objects_ext)].map{|x| File.expand_path(x)}
24
+ creator.register_files(Dir[File.join(path, objects_ext)].map { |x| File.expand_path(x) })
26
25
  end
27
26
 
28
27
  creator.drop_objects
@@ -31,16 +30,16 @@ end
31
30
 
32
31
  require 'rake/hooks'
33
32
 
34
- before "db:migrate" do
33
+ before 'db:migrate' do
35
34
  Rake::Task['db:drop_objects'].invoke
36
35
  end
37
- before "db:rollback" do
36
+ before 'db:rollback' do
38
37
  Rake::Task['db:drop_objects'].invoke
39
38
  end
40
39
 
41
- after "db:migrate" do
40
+ after 'db:migrate' do
42
41
  Rake::Task['db:create_objects'].invoke
43
42
  end
44
- after "db:rollback" do
43
+ after 'db:rollback' do
45
44
  Rake::Task['db:create_objects'].invoke
46
- end
45
+ end
data/test/dummy/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
2
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
3
 
4
- require File.expand_path('../config/application', __FILE__)
4
+ require File.expand_path('config/application', __dir__)
5
5
 
6
6
  Rails.application.load_tasks
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby.exe
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
3
3
  load Gem.bin_path('bundler', 'bundle')
data/test/dummy/bin/rails CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby.exe
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
3
  require_relative '../config/boot'
4
4
  require 'rails/commands'
data/test/dummy/bin/setup CHANGED
@@ -2,15 +2,15 @@
2
2
  require 'pathname'
3
3
 
4
4
  # path to your application root.
5
- APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
5
+ APP_ROOT = Pathname.new File.expand_path('..', __dir__)
6
6
 
7
7
  Dir.chdir APP_ROOT do
8
8
  # This script is a starting point to setup your application.
9
9
  # Add necessary setup steps to this file:
10
10
 
11
- puts "== Installing dependencies =="
12
- system "gem install bundler --conservative"
13
- system "bundle check || bundle install"
11
+ puts '== Installing dependencies =='
12
+ system 'gem install bundler --conservative'
13
+ system 'bundle check || bundle install'
14
14
 
15
15
  # puts "\n== Copying sample files =="
16
16
  # unless File.exist?("config/database.yml")
@@ -18,12 +18,12 @@ Dir.chdir APP_ROOT do
18
18
  # end
19
19
 
20
20
  puts "\n== Preparing database =="
21
- system "bin/rake db:setup"
21
+ system 'bin/rake db:setup'
22
22
 
23
23
  puts "\n== Removing old logs and tempfiles =="
24
- system "rm -f log/*"
25
- system "rm -rf tmp/cache"
24
+ system 'rm -f log/*'
25
+ system 'rm -rf tmp/cache'
26
26
 
27
27
  puts "\n== Restarting application server =="
28
- system "touch tmp/restart.txt"
28
+ system 'touch tmp/restart.txt'
29
29
  end
@@ -1,9 +1,9 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ require File.expand_path('boot', __dir__)
2
2
 
3
3
  require 'rails/all'
4
4
 
5
5
  Bundler.require(*Rails.groups)
6
- require "rails_db_objects"
6
+ require 'rails_db_objects'
7
7
 
8
8
  module Dummy
9
9
  class Application < Rails::Application
@@ -23,4 +23,3 @@ module Dummy
23
23
  config.active_record.raise_in_transactional_callbacks = true
24
24
  end
25
25
  end
26
-
@@ -1,5 +1,5 @@
1
1
  # Set up gems listed in the Gemfile.
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
3
3
 
4
4
  require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
- $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
5
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -1,5 +1,5 @@
1
1
  # Load the Rails application.
2
- require File.expand_path('../application', __FILE__)
2
+ require File.expand_path('application', __dir__)
3
3
 
4
4
  # Initialize the Rails application.
5
5
  Rails.application.initialize!
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class RailsDbObjectsTest < ActiveSupport::TestCase
4
- test "truth" do
4
+ test 'truth' do
5
5
  assert_kind_of Module, RailsDbObjects
6
6
  end
7
7
  end
data/test/test_helper.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # Configure Rails Environment
2
- ENV["RAILS_ENV"] = "test"
2
+ ENV['RAILS_ENV'] = 'test'
3
3
 
4
- require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
5
- ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
6
- require "rails/test_help"
4
+ require File.expand_path('../test/dummy/config/environment.rb', __dir__)
5
+ ActiveRecord::Migrator.migrations_paths = [File.expand_path('../test/dummy/db/migrate', __dir__)]
6
+ require 'rails/test_help'
7
7
 
8
8
  # Filter out Minitest backtrace while allowing backtrace from other libraries
9
9
  # to be shown.
@@ -14,7 +14,7 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
14
14
 
15
15
  # Load fixtures from the engine
16
16
  if ActiveSupport::TestCase.respond_to?(:fixture_path=)
17
- ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
17
+ ActiveSupport::TestCase.fixture_path = File.expand_path('fixtures', __dir__)
18
18
  ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
19
19
  ActiveSupport::TestCase.fixtures :all
20
20
  end
metadata CHANGED
@@ -1,19 +1,61 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_db_objects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-21 00:00:00.000000000 Z
12
- dependencies: []
13
- description: A tool to manage database objects like views, functions, triggers, stored
14
- procedures or assemblies. Inspired by the rails_db_views gem (which you can find
15
- at https://github.com/anykeyh/rails_db_views) and re-using a lot of the code from
16
- there.
11
+ date: 2022-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake-hooks
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.30.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.30.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.11.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.11.1
55
+ description: |-
56
+ A tool to manage database objects like views, functions, triggers, stored procedures or assemblies.
57
+ Inspired by the rails_db_views gem (which you can find at https://github.com/anykeyh/rails_db_views)
58
+ and re-using a lot of the code from there.
17
59
  email:
18
60
  - ''
19
61
  executables: []
@@ -67,7 +109,7 @@ homepage: https://github.com/neongrau/rails_db_objects
67
109
  licenses:
68
110
  - MIT
69
111
  metadata: {}
70
- post_install_message:
112
+ post_install_message:
71
113
  rdoc_options: []
72
114
  require_paths:
73
115
  - lib
@@ -82,13 +124,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
124
  - !ruby/object:Gem::Version
83
125
  version: '0'
84
126
  requirements: []
85
- rubyforge_project:
86
- rubygems_version: 2.6.14
87
- signing_key:
127
+ rubygems_version: 3.2.32
128
+ signing_key:
88
129
  specification_version: 4
89
130
  summary: Drops and Creates database objects via rake/hook before and after any rake
90
131
  db:migrate call.
91
132
  test_files:
133
+ - test/dummy/README.rdoc
134
+ - test/dummy/Rakefile
92
135
  - test/dummy/app/assets/javascripts/application.js
93
136
  - test/dummy/app/assets/stylesheets/application.css
94
137
  - test/dummy/app/controllers/application_controller.rb
@@ -121,7 +164,5 @@ test_files:
121
164
  - test/dummy/public/422.html
122
165
  - test/dummy/public/500.html
123
166
  - test/dummy/public/favicon.ico
124
- - test/dummy/Rakefile
125
- - test/dummy/README.rdoc
126
167
  - test/rails_db_objects_test.rb
127
168
  - test/test_helper.rb