rails_db_objects 0.0.4 → 0.1.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
2
  SHA1:
3
- metadata.gz: afc01e0387360fcb96fba128c134264785d3aa24
4
- data.tar.gz: d6939321cb8ad14aad0542f9b2850a513803d438
3
+ metadata.gz: 236a510b06b887a06f6b4ea958ed92cfb183d401
4
+ data.tar.gz: 7af1e835809cf8108a8b93a743ae8cbca821cb28
5
5
  SHA512:
6
- metadata.gz: b798277b3917e245c816b71e24f0be801391a4b68f1fa5875d0c0ee692eeb6ef09035c41d7ca29642c6501d66aba78a7dea00968c6c7deee61fe7defe6c03c39
7
- data.tar.gz: 5b7dd89cf92e2e3a74e696f2f85eba662df826806798b56ef5d87b6ef077d4b7d9430c9ce7f3fbfe1ec6e086cda6f49ad74d705bc8efb214df9541ab936b4793
6
+ metadata.gz: e8749705009d45ebd899118e3f803587f6061df240dd1508054a9e3a3cb0e00c92783de815686621962b98b03c2ab1da01ae008a602dafc15498bc9026b4c46e
7
+ data.tar.gz: eb95b8974ffd4554d838252f4979ec1138654929792b500a8010f1db0fd2013459a84cc8a4b3ce059e20e1137470cfcf2e798d80406d6c218b9e995a48fc68aa
data/Rakefile CHANGED
@@ -1,34 +1,28 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
6
-
7
- require 'rdoc/task'
8
-
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'RailsDbObjects'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
16
-
17
-
18
-
19
-
20
-
21
-
22
- Bundler::GemHelper.install_tasks
23
-
24
- require 'rake/testtask'
25
-
26
- Rake::TestTask.new(:test) do |t|
27
- t.libs << 'lib'
28
- t.libs << 'test'
29
- t.pattern = 'test/**/*_test.rb'
30
- t.verbose = false
31
- end
32
-
33
-
34
- task default: :test
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RailsDbObjects'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ Bundler::GemHelper.install_tasks
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'lib'
23
+ t.libs << 'test'
24
+ t.pattern = 'test/**/*_test.rb'
25
+ t.verbose = false
26
+ end
27
+
28
+ task default: :test
@@ -1,227 +1,231 @@
1
- class RailsDbObjects::DbObjectsCreator
2
- attr_reader :objects
3
-
4
- def initialize
5
- @objects = {}
6
- end
7
-
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
71
-
72
- @objects[object_type][object_name] = file_obj
73
- end
74
- end
75
-
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]
81
- end
82
- end
83
- end
84
-
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]
90
- end
91
- end
92
- end
93
-
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
99
- end
100
- end
101
- end
102
-
103
-
104
- def drop_object object_type, name, object
105
- return if object[:status] == :loaded
106
-
107
- if object[:status] == :inprogress
108
- raise "Error: Circular file reference! (#{object_type} #{name})"
109
- end
110
-
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]
117
- end
118
-
119
- dbschema = (object[:dbschema] || []).clone
120
- full_name = [dbschema, "[#{name}]"].flatten.reject(&:blank?).compact.join('.')
121
-
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}"
129
- end
130
- end
131
-
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}"
137
- return
138
- else
139
- puts "CONDITION MET FOR #{object_type} #{full_name}"
140
- end
141
- 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"
155
- end
156
- end
157
-
158
- object[:status] = :loaded
159
- end
160
-
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
167
-
168
- # object already loaded.
169
- return if object[:status] == :loaded
170
-
171
- if object[:status] == :inprogress
172
- raise "Error: Circular file reference! (#{object_type} #{name})"
173
- end
174
-
175
- object[:status] = :inprogress
176
-
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
184
-
185
- dbschema = (object[:dbschema] || []).clone
186
- full_name = [dbschema, "[#{name}]"].flatten.reject(&:blank?).compact.join('.')
187
-
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
197
-
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}"
203
- return
204
- else
205
- puts "CONDITION MET FOR #{object_type} #{full_name}"
206
- end
207
- 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"
221
- end
222
- end
223
-
224
- object[:status] = :loaded
225
- end
226
-
227
- end
1
+ module RailsDbObjects
2
+ class DbObjectsCreator
3
+ attr_reader :objects
4
+
5
+ def initialize
6
+ @objects = {}
7
+ end
8
+
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
13
+
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
+ path: file,
24
+ sql_content: sql_content,
25
+ status: :none,
26
+ requires: [],
27
+ silent: false,
28
+ keep: false,
29
+ deleted: false,
30
+ dbschema: Rails.configuration.rails_db_objects[:objects_dbschema],
31
+ dropsql: [],
32
+ createsql: [],
33
+ vanilla: false,
34
+ condition: []
35
+ }
36
+
37
+ # Detect directives in commentary
38
+ directives = extract_from_comments(content_lines)
39
+
40
+ # puts "directives: #{directives.inspect}"
41
+ directives.each { |directive| prepare_directive(file_obj, directive) }
42
+
43
+ @objects[object_type][object_name] = file_obj
44
+ end
45
+ end
46
+
47
+ def drop_objects
48
+ reset_objects_status!
49
+ @objects.keys.each do |object_type|
50
+ @objects[object_type].each do |name, object|
51
+ drop_object(object_type, name, object) unless object[:skip_pre]
52
+ end
53
+ end
54
+ end
55
+
56
+ def create_objects
57
+ reset_objects_status!
58
+ @objects.keys.each do |object_type|
59
+ @objects[object_type].each do |name, object|
60
+ create_object(object_type, name, object) unless object[:skip_post]
61
+ end
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def full(name)
68
+ prefix = @dbschema.blank? ? '' : "#{@dbschema}."
69
+ "#{prefix}#{wrap_name(name)}"
70
+ end
71
+
72
+ def wrap_name(name)
73
+ adapter_name = ActiveRecord::Base.connection.adapter_name
74
+
75
+ case adapter_name
76
+ when 'PostgreSQL'
77
+ "\"#{name}\""
78
+ when 'MySQL'
79
+ "`#{name}`"
80
+ when 'SQLServer'
81
+ "[#{name}]"
82
+ end
83
+ end
84
+
85
+ def extract_from_comments(content_lines)
86
+ dir_lines = content_lines.select { |x| x.strip =~ /^--/ || x.strip =~ /^#/ }.map(&:strip)
87
+ dir_lines.map { |x| /^--/.match?(x) ? x[2..-1] : x[1..-1] }.select { |x| x =~ /^!/ }
88
+ end
89
+
90
+ def prepare_directive(file_obj, directive)
91
+ file_obj[:requires] += directive.split(' ')[1..-1] if /^!require /.match?(directive)
92
+ file_obj[:vanilla] = /^!vanilla/.match?(directive)
93
+ file_obj[:skip_post] = /^!deleted/.match?(directive)
94
+ file_obj[:silent] = /^!silent/.match?(directive)
95
+ file_obj[:skip_pre] = /^!keep/.match?(directive)
96
+ file_obj[:dbschema] = directive.split(' ')[1..-1] if /^!schema/.match?(directive)
97
+ file_obj[:condition] << directive.split(' ')[1..-1].join(' ') if /^!condition /.match?(directive)
98
+ file_obj[:dropsql] << directive.split(' ')[1..-1].join(' ') if /^!dropsql /.match?(directive)
99
+ file_obj[:createsql] << directive.split(' ')[1..-1].join(' ') if /^!createsql /.match?(directive)
100
+ end
101
+
102
+ def reset_objects_status!
103
+ @objects.keys.each do |object_type|
104
+ @objects[object_type].each do |_name, object|
105
+ object[:status] = :none
106
+ end
107
+ end
108
+ end
109
+
110
+ def drop_object(object_type, name, object)
111
+ return if object[:status] == :loaded
112
+
113
+ if object[:status] == :inprogress
114
+ raise "Error: Circular file reference! (#{object_type} #{name})"
115
+ end
116
+
117
+ object[:requires].each do |requirement|
118
+ requires = requirement.split('/', 2)
119
+ required_object = requires.last
120
+ required_type = requires.first.upcase if requires.length == 2
121
+ required_type ||= object_type
122
+ drop_object required_type, required_object, @objects[required_type.upcase][required_object]
123
+ end
124
+
125
+ @dbschema = (object[:dbschema] || []).clone
126
+ full_name = full(name)
127
+
128
+ sql = if object[:vanilla]
129
+ object[:sql_content]
130
+ elsif object[:dropsql].compact.empty?
131
+ "DROP #{object_type} #{full_name};"
132
+ else
133
+ object[:dropsql].compact.join(";\n")
134
+ end
135
+
136
+ begin
137
+ unless object[:condition].compact.empty?
138
+ condition = !ActiveRecord::Base.connection.select_rows(object[:condition].join("\n")).empty?
139
+ if condition
140
+ puts "CONDITION MET FOR #{object_type} #{full_name}"
141
+ else
142
+ puts "CONDITION NOT MET FOR #{object_type} #{full_name}"
143
+ return
144
+ end
145
+ end
146
+ ActiveRecord::Base.connection.execute(sql)
147
+ puts "#{sql}... OK"
148
+ rescue StandardError => e
149
+ unless object[:silent]
150
+ puts '#' * 80
151
+ puts e.message.to_s
152
+ # puts "#"*80
153
+ # puts "#{e.backtrace}"
154
+ puts '#' * 80
155
+ puts "WARNING: #{sql}... ERROR"
156
+ puts '#' * 80
157
+ # else
158
+ # puts "WARNING: #{sql}... SILENT"
159
+ end
160
+ end
161
+
162
+ object[:status] = :loaded
163
+ end
164
+
165
+ def create_object(object_type, name, object)
166
+ # skip empty sql content
167
+ if object[:sql_content].strip.blank?
168
+ puts "#{object_type} #{name} EMPTY... SKIPPING"
169
+ return
170
+ end
171
+
172
+ # object already loaded.
173
+ return if object[:status] == :loaded
174
+
175
+ raise "Error: Circular file reference! (#{object_type} #{name})" if object[:status] == :inprogress
176
+
177
+ object[:status] = :inprogress
178
+
179
+ create_dependencies(object, object_type)
180
+
181
+ @dbschema = (object[:dbschema] || []).clone
182
+ full_name = full(name)
183
+
184
+ sql = if object[:vanilla]
185
+ object[:sql_content]
186
+ elsif object[:createsql].compact.empty?
187
+ "CREATE #{object_type} #{full_name}\n#{object[:sql_content]}"
188
+ else
189
+ object[:createsql].compact.join("\n")
190
+ end
191
+
192
+ begin
193
+ unless object[:condition].compact.empty?
194
+ condition = ActiveRecord::Base.connection.select_rows(object[:condition].join("\n")).empty?
195
+ if condition
196
+ puts "CONDITION MET FOR #{object_type} #{full_name}"
197
+ else
198
+ puts "CONDITION NOT MET FOR #{object_type} #{full_name}"
199
+ return
200
+ end
201
+ end
202
+ ActiveRecord::Base.connection.execute(sql.to_s)
203
+ puts "CREATE #{object_type} #{full_name}... OK"
204
+ rescue StandardError => e
205
+ unless object[:silent]
206
+ puts '#' * 80
207
+ puts e.message.to_s
208
+ # puts "#"*80
209
+ # puts "#{e.backtrace}"
210
+ puts '#' * 80
211
+ puts "WARNING: CREATE #{object_type} #{full_name}... ERROR"
212
+ puts '#' * 80
213
+ # else
214
+ # puts "WARNING: CREATE #{object_type} #{full_name}... SILENT"
215
+ end
216
+ end
217
+
218
+ object[:status] = :loaded
219
+ end
220
+
221
+ def create_dependencies(object, object_type)
222
+ object[:requires].each do |requirement|
223
+ requires = requirement.split('/', 2)
224
+ required_object = requires.last
225
+ required_type = requires.first.upcase if requires.length == 2
226
+ required_type ||= object_type
227
+ create_object required_type, required_object, @objects[required_type.upcase][required_object]
228
+ end
229
+ end
230
+ end
231
+ end
@@ -1,15 +1,15 @@
1
- class Railtie < Rails::Railtie
2
- railtie_name :rails_db_objects
3
-
4
- config.rails_db_objects = ActiveSupport::OrderedHash.new
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"
9
- app.config.rails_db_objects[:objects_dbschema] = ['dbo']
10
- end
11
-
12
- rake_tasks do
13
- load "tasks/rails_db_objects_tasks.rake"
14
- end
15
- end
1
+ class Railtie < Rails::Railtie
2
+ railtie_name :rails_db_objects
3
+
4
+ config.rails_db_objects = ActiveSupport::OrderedHash.new
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'
9
+ app.config.rails_db_objects[:objects_dbschema] = ['dbo']
10
+ end
11
+
12
+ rake_tasks do
13
+ load 'tasks/rails_db_objects_tasks.rake'
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
- module RailsDbObjects
2
- VERSION = "0.0.4"
3
- end
1
+ module RailsDbObjects
2
+ VERSION = '0.1.1'.freeze
3
+ end
@@ -1,46 +1,45 @@
1
- namespace :db do
2
-
3
- desc "Generate all the database objects of the current project"
4
- task :create_objects => :environment do
5
- creator = RailsDbObjects::DbObjectsCreator.new
6
-
7
- objects_path, objects_ext = Rails.configuration.rails_db_objects[:objects_path], Rails.configuration.rails_db_objects[:objects_ext]
8
-
9
- objects_path.each do |path|
10
- creator.register_files Dir[File.join(path, objects_ext)].map {|x|
11
- File.expand_path(x)
12
- }
13
- end
14
-
15
- creator.create_objects
16
- end
17
-
18
- desc "Drop all the database objects of the current project"
19
- task :drop_objects => :environment do
20
- creator = RailsDbObjects::DbObjectsCreator.new
21
-
22
- objects_path, objects_ext = Rails.configuration.rails_db_objects[:objects_path], Rails.configuration.rails_db_objects[:objects_ext]
23
-
24
- objects_path.each do |path|
25
- creator.register_files Dir[File.join(path, objects_ext)].map{|x| File.expand_path(x)}
26
- end
27
-
28
- creator.drop_objects
29
- end
30
- end
31
-
32
- require 'rake/hooks'
33
-
34
- before "db:migrate" do
35
- Rake::Task['db:drop_objects'].invoke
36
- end
37
- before "db:rollback" do
38
- Rake::Task['db:drop_objects'].invoke
39
- end
40
-
41
- after "db:migrate" do
42
- Rake::Task['db:create_objects'].invoke
43
- end
44
- after "db:rollback" do
45
- Rake::Task['db:create_objects'].invoke
46
- end
1
+ namespace :db do
2
+ desc 'Generate all the database objects of the current project'
3
+ task create_objects: :environment do
4
+ creator = RailsDbObjects::DbObjectsCreator.new
5
+
6
+ objects_path = Rails.configuration.rails_db_objects[:objects_path]
7
+ objects_ext = Rails.configuration.rails_db_objects[:objects_ext]
8
+
9
+ objects_path.each do |path|
10
+ creator.register_files(Dir[File.join(path, objects_ext)].map { |x| File.expand_path(x) })
11
+ end
12
+
13
+ creator.create_objects
14
+ end
15
+
16
+ desc 'Drop all the database objects of the current project'
17
+ task drop_objects: :environment do
18
+ creator = RailsDbObjects::DbObjectsCreator.new
19
+
20
+ objects_path = Rails.configuration.rails_db_objects[:objects_path]
21
+ objects_ext = Rails.configuration.rails_db_objects[:objects_ext]
22
+
23
+ objects_path.each do |path|
24
+ creator.register_files(Dir[File.join(path, objects_ext)].map { |x| File.expand_path(x) })
25
+ end
26
+
27
+ creator.drop_objects
28
+ end
29
+ end
30
+
31
+ require 'rake/hooks'
32
+
33
+ before 'db:migrate' do
34
+ Rake::Task['db:drop_objects'].invoke
35
+ end
36
+ before 'db:rollback' do
37
+ Rake::Task['db:drop_objects'].invoke
38
+ end
39
+
40
+ after 'db:migrate' do
41
+ Rake::Task['db:create_objects'].invoke
42
+ end
43
+ after 'db:rollback' do
44
+ Rake::Task['db:create_objects'].invoke
45
+ end
data/test/dummy/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require File.expand_path('../config/application', __FILE__)
5
-
6
- Rails.application.load_tasks
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('config/application', __dir__)
5
+
6
+ Rails.application.load_tasks
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env ruby.exe
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
- load Gem.bin_path('bundler', 'bundle')
1
+ #!/usr/bin/env ruby.exe
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
3
+ load Gem.bin_path('bundler', 'bundle')
data/test/dummy/bin/rails CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby.exe
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
3
- require_relative '../config/boot'
4
- require 'rails/commands'
1
+ #!/usr/bin/env ruby.exe
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
data/test/dummy/bin/rake CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby.exe
2
- require_relative '../config/boot'
3
- require 'rake'
4
- Rake.application.run
1
+ #!/usr/bin/env ruby.exe
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
data/test/dummy/bin/setup CHANGED
@@ -1,29 +1,29 @@
1
- #!/usr/bin/env ruby.exe
2
- require 'pathname'
3
-
4
- # path to your application root.
5
- APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
-
7
- Dir.chdir APP_ROOT do
8
- # This script is a starting point to setup your application.
9
- # Add necessary setup steps to this file:
10
-
11
- puts "== Installing dependencies =="
12
- system "gem install bundler --conservative"
13
- system "bundle check || bundle install"
14
-
15
- # puts "\n== Copying sample files =="
16
- # unless File.exist?("config/database.yml")
17
- # system "cp config/database.yml.sample config/database.yml"
18
- # end
19
-
20
- puts "\n== Preparing database =="
21
- system "bin/rake db:setup"
22
-
23
- puts "\n== Removing old logs and tempfiles =="
24
- system "rm -f log/*"
25
- system "rm -rf tmp/cache"
26
-
27
- puts "\n== Restarting application server =="
28
- system "touch tmp/restart.txt"
29
- end
1
+ #!/usr/bin/env ruby.exe
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('..', __dir__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts '== Installing dependencies =='
12
+ system 'gem install bundler --conservative'
13
+ system 'bundle check || bundle install'
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system 'bin/rake db:setup'
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system 'rm -f log/*'
25
+ system 'rm -rf tmp/cache'
26
+
27
+ puts "\n== Restarting application server =="
28
+ system 'touch tmp/restart.txt'
29
+ end
@@ -1,26 +1,25 @@
1
- require File.expand_path('../boot', __FILE__)
2
-
3
- require 'rails/all'
4
-
5
- Bundler.require(*Rails.groups)
6
- require "rails_db_objects"
7
-
8
- module Dummy
9
- class Application < Rails::Application
10
- # Settings in config/environments/* take precedence over those specified here.
11
- # Application configuration should go into files in config/initializers
12
- # -- all .rb files in that directory are automatically loaded.
13
-
14
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
- # config.time_zone = 'Central Time (US & Canada)'
17
-
18
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
- # config.i18n.default_locale = :de
21
-
22
- # Do not swallow errors in after_commit/after_rollback callbacks.
23
- config.active_record.raise_in_transactional_callbacks = true
24
- end
25
- end
26
-
1
+ require File.expand_path('boot', __dir__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require 'rails_db_objects'
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
+ # config.time_zone = 'Central Time (US & Canada)'
17
+
18
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
+ # config.i18n.default_locale = :de
21
+
22
+ # Do not swallow errors in after_commit/after_rollback callbacks.
23
+ config.active_record.raise_in_transactional_callbacks = true
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
- # Set up gems listed in the Gemfile.
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
-
4
- require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
- $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -1,5 +1,5 @@
1
- # Load the Rails application.
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the Rails application.
5
- Rails.application.initialize!
1
+ # Load the Rails application.
2
+ require File.expand_path('application', __dir__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -1,7 +1,7 @@
1
- require 'test_helper'
2
-
3
- class RailsDbObjectsTest < ActiveSupport::TestCase
4
- test "truth" do
5
- assert_kind_of Module, RailsDbObjects
6
- end
7
- end
1
+ require 'test_helper'
2
+
3
+ class RailsDbObjectsTest < ActiveSupport::TestCase
4
+ test 'truth' do
5
+ assert_kind_of Module, RailsDbObjects
6
+ end
7
+ end
data/test/test_helper.rb CHANGED
@@ -1,20 +1,20 @@
1
- # Configure Rails Environment
2
- ENV["RAILS_ENV"] = "test"
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"
7
-
8
- # Filter out Minitest backtrace while allowing backtrace from other libraries
9
- # to be shown.
10
- Minitest.backtrace_filter = Minitest::BacktraceFilter.new
11
-
12
- # Load support files
13
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
14
-
15
- # Load fixtures from the engine
16
- if ActiveSupport::TestCase.respond_to?(:fixture_path=)
17
- ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
18
- ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
19
- ActiveSupport::TestCase.fixtures :all
20
- end
1
+ # Configure Rails Environment
2
+ ENV['RAILS_ENV'] = 'test'
3
+
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
+
8
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
9
+ # to be shown.
10
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
11
+
12
+ # Load support files
13
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
14
+
15
+ # Load fixtures from the engine
16
+ if ActiveSupport::TestCase.respond_to?(:fixture_path=)
17
+ ActiveSupport::TestCase.fixture_path = File.expand_path('fixtures', __dir__)
18
+ ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
19
+ ActiveSupport::TestCase.fixtures :all
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: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
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: 2018-10-18 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
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: []
@@ -83,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
125
  version: '0'
84
126
  requirements: []
85
127
  rubyforge_project:
86
- rubygems_version: 2.6.14
128
+ rubygems_version: 2.6.14.1
87
129
  signing_key:
88
130
  specification_version: 4
89
131
  summary: Drops and Creates database objects via rake/hook before and after any rake