trusty-layouts-extension 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/tasks/layouts_extension_tasks.rake +4 -4
- data/trusty-layouts-extension.gemspec +1 -1
- metadata +8 -29
- data/vendor/plugins/rails_upgrade/MIT-LICENSE +0 -20
- data/vendor/plugins/rails_upgrade/README.rdoc +0 -26
- data/vendor/plugins/rails_upgrade/Rakefile +0 -22
- data/vendor/plugins/rails_upgrade/init.rb +0 -2
- data/vendor/plugins/rails_upgrade/install.rb +0 -38
- data/vendor/plugins/rails_upgrade/lib/application_checker.rb +0 -506
- data/vendor/plugins/rails_upgrade/lib/gemfile_generator.rb +0 -95
- data/vendor/plugins/rails_upgrade/lib/new_configuration_generator.rb +0 -59
- data/vendor/plugins/rails_upgrade/lib/rails_upgrade.rb +0 -0
- data/vendor/plugins/rails_upgrade/lib/routes_upgrader.rb +0 -344
- data/vendor/plugins/rails_upgrade/lib/tasks/rails_upgrade_tasks.rake +0 -79
- data/vendor/plugins/rails_upgrade/test/application_checker_test.rb +0 -344
- data/vendor/plugins/rails_upgrade/test/gemfile_generator_test.rb +0 -72
- data/vendor/plugins/rails_upgrade/test/new_configuration_generator_test.rb +0 -63
- data/vendor/plugins/rails_upgrade/test/routes_upgrader_test.rb +0 -218
- data/vendor/plugins/rails_upgrade/test/test_helper.rb +0 -5
- data/vendor/plugins/rails_upgrade/uninstall.rb +0 -1
@@ -1,506 +0,0 @@
|
|
1
|
-
require 'open3'
|
2
|
-
|
3
|
-
module Rails
|
4
|
-
module Upgrading
|
5
|
-
class ApplicationChecker
|
6
|
-
def initialize
|
7
|
-
@issues = []
|
8
|
-
|
9
|
-
raise NotInRailsAppError unless in_rails_app?
|
10
|
-
end
|
11
|
-
|
12
|
-
def in_rails_app?
|
13
|
-
File.exist?("config/environment.rb")
|
14
|
-
end
|
15
|
-
|
16
|
-
# Run all the check methods
|
17
|
-
def run
|
18
|
-
# Ruby 1.8 returns method names as strings whereas 1.9 uses symbols
|
19
|
-
the_methods = (self.public_methods - Object.methods) - [:run, :initialize, "run", "initialize"]
|
20
|
-
|
21
|
-
the_methods.each {|m| send m }
|
22
|
-
end
|
23
|
-
|
24
|
-
# Check for deprecated ActiveRecord calls
|
25
|
-
def check_ar_methods
|
26
|
-
files = []
|
27
|
-
["find(:all", "find(:first", "find.*:conditions =>", ":joins =>"].each do |v|
|
28
|
-
lines = grep_for(v, "app/")
|
29
|
-
files += extract_filenames(lines) || []
|
30
|
-
end
|
31
|
-
|
32
|
-
unless files.empty?
|
33
|
-
alert(
|
34
|
-
"Soon-to-be-deprecated ActiveRecord calls",
|
35
|
-
"Methods such as find(:all), find(:first), finds with conditions, and the :joins option will soon be deprecated.",
|
36
|
-
"http://m.onkey.org/2010/1/22/active-record-query-interface",
|
37
|
-
files
|
38
|
-
)
|
39
|
-
end
|
40
|
-
|
41
|
-
lines = grep_for("named_scope", "app/models/")
|
42
|
-
files = extract_filenames(lines)
|
43
|
-
|
44
|
-
unless files.empty?
|
45
|
-
alert(
|
46
|
-
"named_scope is now just scope",
|
47
|
-
"The named_scope method has been renamed to just scope.",
|
48
|
-
"http://github.com/rails/rails/commit/d60bb0a9e4be2ac0a9de9a69041a4ddc2e0cc914",
|
49
|
-
files
|
50
|
-
)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def check_validation_on_methods
|
55
|
-
files = []
|
56
|
-
|
57
|
-
["validate_on_create", "validate_on_update"].each do |v|
|
58
|
-
lines = grep_for(v, "app/models/")
|
59
|
-
files += extract_filenames(lines) || []
|
60
|
-
end
|
61
|
-
|
62
|
-
unless files.empty?
|
63
|
-
alert(
|
64
|
-
"Updated syntax for validate_on_* methods",
|
65
|
-
"Validate-on-callback methods (validate_on_create/validate_on_destroy) have been changed to validate :x, :on => :create",
|
66
|
-
"https://rails.lighthouseapp.com/projects/8994/tickets/3880-validate_on_create-and-validate_on_update-no-longer-seem-to-exist",
|
67
|
-
files
|
68
|
-
)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def check_before_validation_on_methods
|
73
|
-
files = []
|
74
|
-
|
75
|
-
%w(before_validation_on_create before_validation_on_update).each do |v|
|
76
|
-
lines = grep_for(v, "app/models/")
|
77
|
-
files += extract_filenames(lines) || []
|
78
|
-
end
|
79
|
-
|
80
|
-
unless files.empty?
|
81
|
-
alert(
|
82
|
-
"Updated syntax for before_validation_on_* methods",
|
83
|
-
"before_validation_on_* methods have been changed to before_validation(:on => :create/:update) { ... }",
|
84
|
-
"https://rails.lighthouseapp.com/projects/8994/tickets/4699-before_validation_on_create-and-before_validation_on_update-doesnt-exist",
|
85
|
-
files
|
86
|
-
)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# Check for deprecated router syntax
|
91
|
-
def check_routes
|
92
|
-
lines = ["map\\.", "ActionController::Routing::Routes", "\\.resources"].map do |v|
|
93
|
-
grep_for(v, "config/routes.rb").empty? ? nil : true
|
94
|
-
end.compact
|
95
|
-
|
96
|
-
unless lines.empty?
|
97
|
-
alert(
|
98
|
-
"Old router API",
|
99
|
-
"The router API has totally changed.",
|
100
|
-
"http://yehudakatz.com/2009/12/26/the-rails-3-router-rack-it-up/",
|
101
|
-
"config/routes.rb"
|
102
|
-
)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
# Check for deprecated test_help require
|
107
|
-
def check_test_help
|
108
|
-
files = []
|
109
|
-
|
110
|
-
# Hate to duplicate code, but we have to double quote this one...
|
111
|
-
lines = grep_for("\'test_help\'", "test/", true)
|
112
|
-
files += extract_filenames(lines) || []
|
113
|
-
|
114
|
-
lines = grep_for("\"test_help\"", "test/")
|
115
|
-
files += extract_filenames(lines) || []
|
116
|
-
|
117
|
-
files.uniq!
|
118
|
-
|
119
|
-
unless files.empty?
|
120
|
-
alert(
|
121
|
-
"Deprecated test_help path",
|
122
|
-
"You now must require 'rails/test_help' not just 'test_help'.",
|
123
|
-
"http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices",
|
124
|
-
files
|
125
|
-
)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
# Check for old (pre-application.rb) environment.rb file
|
130
|
-
def check_environment
|
131
|
-
unless File.exist?("config/application.rb")
|
132
|
-
alert(
|
133
|
-
"New file needed: config/application.rb",
|
134
|
-
"You need to add a config/application.rb.",
|
135
|
-
"http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade",
|
136
|
-
"config/application.rb"
|
137
|
-
)
|
138
|
-
end
|
139
|
-
|
140
|
-
lines = grep_for("config.", "config/environment.rb")
|
141
|
-
|
142
|
-
unless lines.empty?
|
143
|
-
alert(
|
144
|
-
"Old environment.rb",
|
145
|
-
"environment.rb doesn't do what it used to; you'll need to move some of that into application.rb.",
|
146
|
-
"http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade",
|
147
|
-
"config/environment.rb"
|
148
|
-
)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
# Check for deprecated constants
|
153
|
-
def check_deprecated_constants
|
154
|
-
files = []
|
155
|
-
["RAILS_ENV", "RAILS_ROOT", "RAILS_DEFAULT_LOGGER"].each do |v|
|
156
|
-
lines = grep_for(v, "app/")
|
157
|
-
files += extract_filenames(lines) || []
|
158
|
-
|
159
|
-
lines = grep_for(v, "lib/")
|
160
|
-
files += extract_filenames(lines) || []
|
161
|
-
end
|
162
|
-
|
163
|
-
unless files.empty?
|
164
|
-
alert(
|
165
|
-
"Deprecated constant(s)",
|
166
|
-
"Constants like Rails.env, Rails.root, and RAILS_DEFAULT_LOGGER are now deprecated.",
|
167
|
-
"http://litanyagainstfear.com/blog/2010/02/03/the-rails-module/",
|
168
|
-
files.uniq
|
169
|
-
)
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
# Check for old-style config.gem calls
|
174
|
-
def check_gems
|
175
|
-
lines = grep_for("config.gem ", "config/*.rb")
|
176
|
-
lines += grep_for("config.gem ", "config/**/*.rb")
|
177
|
-
files = extract_filenames(lines)
|
178
|
-
|
179
|
-
unless files.empty?
|
180
|
-
alert(
|
181
|
-
"Old gem bundling (config.gems)",
|
182
|
-
"The old way of bundling is gone now. You need a Gemfile for bundler.",
|
183
|
-
"http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade",
|
184
|
-
files
|
185
|
-
)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
# Checks for old mailer syntax in both mailer classes and those
|
190
|
-
# classes utilizing the mailers
|
191
|
-
def check_mailers
|
192
|
-
lines = grep_for("deliver_", "app/models/ #{base_path}app/controllers/ #{base_path}app/observers/")
|
193
|
-
files = extract_filenames(lines)
|
194
|
-
|
195
|
-
unless files.empty?
|
196
|
-
alert(
|
197
|
-
"Deprecated ActionMailer API",
|
198
|
-
"You're using the old ActionMailer API to send e-mails in a controller, model, or observer.",
|
199
|
-
"http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3",
|
200
|
-
files
|
201
|
-
)
|
202
|
-
end
|
203
|
-
|
204
|
-
files = []
|
205
|
-
["recipients ", "attachment(?!s) ", "(?<!:)subject ", "(?<!:)from "].each do |v|
|
206
|
-
lines = grep_for_with_perl_regex(v, "app/models/")
|
207
|
-
files += extract_filenames(lines) || []
|
208
|
-
end
|
209
|
-
|
210
|
-
unless files.empty?
|
211
|
-
alert(
|
212
|
-
"Old ActionMailer class API",
|
213
|
-
"You're using the old API in a mailer class.",
|
214
|
-
"http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3",
|
215
|
-
files
|
216
|
-
)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
# Checks for old-style generators
|
221
|
-
def check_generators
|
222
|
-
generators = Dir.glob(base_path + "vendor/plugins/**/generators/**/")
|
223
|
-
|
224
|
-
unless generators.empty?
|
225
|
-
files = generators.reject do |g|
|
226
|
-
grep_for("def manifest", g).empty?
|
227
|
-
end.compact
|
228
|
-
|
229
|
-
unless files.empty?
|
230
|
-
alert(
|
231
|
-
"Old Rails generator API",
|
232
|
-
"A plugin in the app is using the old generator API (a new one may be available at http://github.com/trydionel/rails3-generators).",
|
233
|
-
"http://blog.plataformatec.com.br/2010/01/discovering-rails-3-generators/",
|
234
|
-
files
|
235
|
-
)
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
# Checks a list of known broken plugins and gems
|
241
|
-
def check_plugins
|
242
|
-
# This list is off the wiki; will need to be updated often, esp. since RSpec is working on it
|
243
|
-
bad_plugins = ["rspec", "rspec-rails", "hoptoad", "authlogic", "nifty-generators",
|
244
|
-
"restful_authentication", "searchlogic", "cucumber", "cucumber-rails", "devise",
|
245
|
-
"inherited_resources"]
|
246
|
-
|
247
|
-
bad_plugins = bad_plugins.map do |p|
|
248
|
-
p if File.exist?("#{base_path}vendor/plugins/#{p}") || !Dir.glob("#{base_path}vendor/gems/#{p}-*").empty?
|
249
|
-
end.compact
|
250
|
-
|
251
|
-
unless bad_plugins.empty?
|
252
|
-
alert(
|
253
|
-
"Known broken plugins",
|
254
|
-
"At least one plugin in your app is broken (according to the wiki). Most of project maintainers are rapidly working towards compatibility, but do be aware you may encounter issues.",
|
255
|
-
"http://wiki.rubyonrails.org/rails/version3/plugins_and_gems",
|
256
|
-
bad_plugins
|
257
|
-
)
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
# Checks for old-style ERb helpers
|
262
|
-
def check_old_helpers
|
263
|
-
|
264
|
-
lines = grep_for("<% .*content_tag.* do.*%>", "app/views/**/*")
|
265
|
-
lines += grep_for("<% .*javascript_tag.* do.*%>", "app/views/**/*")
|
266
|
-
lines += grep_for("<% .*form_for.* do.*%>", "app/views/**/*")
|
267
|
-
lines += grep_for("<% .*form_tag.* do.*%>", "app/views/**/*")
|
268
|
-
lines += grep_for("<% .*fields_for.* do.*%>", "app/views/**/*")
|
269
|
-
lines += grep_for("<% .*field_set_tag.* do.*%>", "app/views/**/*")
|
270
|
-
|
271
|
-
files = extract_filenames(lines)
|
272
|
-
|
273
|
-
if !files.blank?
|
274
|
-
alert(
|
275
|
-
"Deprecated ERb helper calls",
|
276
|
-
"Block helpers that use concat (e.g., form_for) should use <%= instead of <%. The current form will continue to work for now, but you will get deprecation warnings since this form will go away in the future.",
|
277
|
-
"http://weblog.rubyonrails.org/",
|
278
|
-
files
|
279
|
-
)
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
# Checks for old-style AJAX helpers
|
284
|
-
def check_old_ajax_helpers
|
285
|
-
files = []
|
286
|
-
['link_to_remote','form_remote_tag','remote_form_for', 'form_remote_for'].each do |type|
|
287
|
-
lines = grep_for(type, "app/views/**/*")
|
288
|
-
inner_files = extract_filenames(lines)
|
289
|
-
files += inner_files unless inner_files.nil?
|
290
|
-
end
|
291
|
-
|
292
|
-
unless files.empty?
|
293
|
-
alert(
|
294
|
-
"Deprecated AJAX helper calls",
|
295
|
-
"AJAX javascript helpers have been switched to be unobtrusive and use :remote => true instead of having a seperate function to handle remote requests.",
|
296
|
-
"http://blog.jordanwest.me/modest-rubyist-archive/rails-3-ujs-and-csrf-meta-tags",
|
297
|
-
files
|
298
|
-
)
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
# Checks for old cookie secret settings
|
303
|
-
def check_old_cookie_secret
|
304
|
-
lines = grep_for("ActionController::Base.cookie_verifier_secret = ", "config/**/*")
|
305
|
-
files = extract_filenames(lines)
|
306
|
-
|
307
|
-
unless files.empty?
|
308
|
-
alert(
|
309
|
-
"Deprecated cookie secret setting",
|
310
|
-
"Previously, cookie secret was set directly on ActionController::Base; it's now config.secret_token.",
|
311
|
-
"http://lindsaar.net/2010/4/7/rails_3_session_secret_and_session_store",
|
312
|
-
files
|
313
|
-
)
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
def check_old_session_secret
|
318
|
-
lines = grep_for("ActionController::Base.session = {", "config/**/*")
|
319
|
-
files = extract_filenames(lines)
|
320
|
-
|
321
|
-
unless files.empty?
|
322
|
-
alert(
|
323
|
-
"Deprecated session secret setting",
|
324
|
-
"Previously, session secret was set directly on ActionController::Base; it's now config.secret_token.",
|
325
|
-
"http://lindsaar.net/2010/4/7/rails_3_session_secret_and_session_store",
|
326
|
-
files
|
327
|
-
)
|
328
|
-
end
|
329
|
-
end
|
330
|
-
|
331
|
-
# Checks for old session settings
|
332
|
-
def check_old_session_setting
|
333
|
-
lines = grep_for("ActionController::Base.session_store", "config/**/*")
|
334
|
-
files = extract_filenames(lines)
|
335
|
-
|
336
|
-
unless files.empty?
|
337
|
-
alert(
|
338
|
-
"Old session store setting",
|
339
|
-
"Previously, session store was set directly on ActionController::Base; it's now config.session_store :whatever.",
|
340
|
-
"http://lindsaar.net/2010/4/7/rails_3_session_secret_and_session_store",
|
341
|
-
files
|
342
|
-
)
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
#Check for old ActionMailer :sent_on attributes
|
347
|
-
def check_old_action_mailer_sent_on_setting
|
348
|
-
files = []
|
349
|
-
lines = grep_for("sent_on", "app/*")
|
350
|
-
files += extract_filenames(lines) || []
|
351
|
-
|
352
|
-
unless files.empty?
|
353
|
-
alert(
|
354
|
-
"Deprecated ActionMailer attribute :sent_on",
|
355
|
-
"Using the new mailer API, you can specify :date to the mail method.",
|
356
|
-
"http://stackoverflow.com/questions/7367185/weird-error-when-delivering-mail-undefined-method-index-for-2011-09-09-2215",
|
357
|
-
files
|
358
|
-
)
|
359
|
-
end
|
360
|
-
end
|
361
|
-
def check_old_filter_parameter
|
362
|
-
files = []
|
363
|
-
lines = grep_for("filter_parameter_logging", "app/controllers/*")
|
364
|
-
files += extract_filenames(lines) || []
|
365
|
-
|
366
|
-
unless files.empty?
|
367
|
-
alert(
|
368
|
-
"Deprecated filter_parameter_logging calls",
|
369
|
-
"The list of filtered parameters are now stored in /config/application.rb. For example: config.filter_parameters += [:password]",
|
370
|
-
"http://asciicasts.com/episodes/224-controllers-in-rails-3",
|
371
|
-
files
|
372
|
-
)
|
373
|
-
end
|
374
|
-
end
|
375
|
-
private
|
376
|
-
def grep_for_with_perl_regex(text, where = "./", double_quote = false)
|
377
|
-
grep_for(text, where, double_quote, true)
|
378
|
-
end
|
379
|
-
|
380
|
-
# Find a string in a set of files; calls +find_with_grep+ and +find_with_rak+
|
381
|
-
# depending on platform.
|
382
|
-
#
|
383
|
-
# TODO: Figure out if this works on Windows.
|
384
|
-
def grep_for(text, where = "./", double_quote = false, perl_regex = false)
|
385
|
-
# If they're on Windows, they probably don't have grep.
|
386
|
-
@probably_has_grep ||= (Config::CONFIG['host_os'].downcase =~ /mswin|windows|mingw/).nil?
|
387
|
-
|
388
|
-
# protect against double root paths in Rails 3
|
389
|
-
where.gsub!(Regexp.new(base_path),'')
|
390
|
-
|
391
|
-
lines = if @probably_has_grep
|
392
|
-
find_with_grep(text, base_path + where, double_quote, perl_regex)
|
393
|
-
else
|
394
|
-
find_with_rak(text, base_path + where, double_quote)
|
395
|
-
end
|
396
|
-
|
397
|
-
# ignore comments
|
398
|
-
lines.gsub /^(\/[^:]+:)?\s*#.+$/m, ""
|
399
|
-
end
|
400
|
-
|
401
|
-
# Sets a base path for finding files; mostly for testing
|
402
|
-
def base_path
|
403
|
-
Dir.pwd + "/"
|
404
|
-
end
|
405
|
-
|
406
|
-
# Use the grep utility to find a string in a set of files
|
407
|
-
def find_with_grep(text, where, double_quote, perl_regex = false)
|
408
|
-
value = ""
|
409
|
-
# Specifically double quote for finding 'test_help'
|
410
|
-
command = if double_quote
|
411
|
-
"grep -rH #{"-P" if perl_regex} \"#{text}\" #{where} | grep -v \.svn"
|
412
|
-
else
|
413
|
-
"grep -rH #{"-P" if perl_regex} '#{text}' #{where} | grep -v \.svn"
|
414
|
-
end
|
415
|
-
|
416
|
-
Open3.popen3(command) do |stdin, stdout, stderr|
|
417
|
-
value = stdout.read
|
418
|
-
end
|
419
|
-
value
|
420
|
-
end
|
421
|
-
|
422
|
-
# Use the rak gem to grep the files (not yet implemented)
|
423
|
-
def find_with_rak(text, where, double_quote)
|
424
|
-
value = ""
|
425
|
-
Open3.popen3("rak --nogroup -l '#{Regexp.escape(text)}' #{where}") do |stdin, stdout, stderr|
|
426
|
-
value = stdout.read
|
427
|
-
end
|
428
|
-
value
|
429
|
-
end
|
430
|
-
|
431
|
-
# Extract the filenames from the grep output
|
432
|
-
def extract_filenames(output)
|
433
|
-
if @probably_has_grep
|
434
|
-
filenames = extract_filenames_from_grep(output)
|
435
|
-
else
|
436
|
-
filenames = extract_filenames_from_rak(output)
|
437
|
-
end
|
438
|
-
|
439
|
-
filenames.compact.map do |f|
|
440
|
-
f.gsub(base_path, "")
|
441
|
-
end
|
442
|
-
end
|
443
|
-
|
444
|
-
def extract_filenames_from_grep(output)
|
445
|
-
return [] if output.empty?
|
446
|
-
|
447
|
-
output.split("\n").map do |fn|
|
448
|
-
if m = fn.match(/^(.+?):/)
|
449
|
-
m[1]
|
450
|
-
end
|
451
|
-
end.compact.uniq
|
452
|
-
end
|
453
|
-
|
454
|
-
def extract_filenames_from_rak(output)
|
455
|
-
return [] if output.empty?
|
456
|
-
|
457
|
-
output.split("\n").uniq
|
458
|
-
end
|
459
|
-
|
460
|
-
# Terminal colors, borrowed from Thor
|
461
|
-
CLEAR = "\e[0m"
|
462
|
-
BOLD = "\e[1m"
|
463
|
-
RED = "\e[31m"
|
464
|
-
YELLOW = "\e[33m"
|
465
|
-
CYAN = "\e[36m"
|
466
|
-
WHITE = "\e[37m"
|
467
|
-
|
468
|
-
# Show an upgrade alert to the user
|
469
|
-
def alert(title, text, more_info_url, culprits)
|
470
|
-
if Config::CONFIG['host_os'].downcase =~ /mswin|windows|mingw/
|
471
|
-
basic_alert(title, text, more_info_url, culprits)
|
472
|
-
else
|
473
|
-
color_alert(title, text, more_info_url, culprits)
|
474
|
-
end
|
475
|
-
end
|
476
|
-
|
477
|
-
# Show an upgrade alert to the user. If we're on Windows, we can't
|
478
|
-
# use terminal colors, hence this method.
|
479
|
-
def basic_alert(title, text, more_info_url, culprits)
|
480
|
-
puts "** " + title
|
481
|
-
puts text
|
482
|
-
puts "More information: #{more_info_url}"
|
483
|
-
puts
|
484
|
-
puts "The culprits: "
|
485
|
-
Array(culprits).each do |c|
|
486
|
-
puts "\t- #{c}"
|
487
|
-
end
|
488
|
-
puts
|
489
|
-
end
|
490
|
-
|
491
|
-
# Show a colorful alert to the user
|
492
|
-
def color_alert(title, text, more_info_url, culprits)
|
493
|
-
puts "#{RED}#{BOLD}#{title}#{CLEAR}"
|
494
|
-
puts "#{WHITE}#{text}"
|
495
|
-
puts "#{BOLD}More information:#{CLEAR} #{CYAN}#{more_info_url}"
|
496
|
-
puts
|
497
|
-
puts "#{WHITE}The culprits: "
|
498
|
-
Array(culprits).each do |c|
|
499
|
-
puts "#{YELLOW}\t- #{c}"
|
500
|
-
end
|
501
|
-
ensure
|
502
|
-
puts "#{CLEAR}"
|
503
|
-
end
|
504
|
-
end
|
505
|
-
end
|
506
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
module Rails
|
2
|
-
module Upgrading
|
3
|
-
class GemfileGenerator
|
4
|
-
def generate_new_gemfile
|
5
|
-
if has_environment?
|
6
|
-
generate_gemfile
|
7
|
-
else
|
8
|
-
raise FileNotFoundError, "Can't find environment.rb [config/environment.rb]!"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def has_environment?
|
13
|
-
File.exists?("config/environment.rb")
|
14
|
-
end
|
15
|
-
|
16
|
-
def environment_code
|
17
|
-
File.open("config/environment.rb").read
|
18
|
-
end
|
19
|
-
|
20
|
-
def generate_gemfile
|
21
|
-
environment_file = environment_code
|
22
|
-
|
23
|
-
# Get each line that starts with config.gem
|
24
|
-
gem_lines = environment_file.split("\n").select {|l| l =~ /^\s*config\.gem/}
|
25
|
-
|
26
|
-
# Toss those lines to a generator class; the lines are evaluated in the
|
27
|
-
# context of that instance.
|
28
|
-
config = GemfileGenerator.new
|
29
|
-
config.instance_eval(gem_lines.join("\n"))
|
30
|
-
|
31
|
-
config.output
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class GemfileGenerator
|
36
|
-
# Creates a target for the config.gem calls
|
37
|
-
def config
|
38
|
-
self
|
39
|
-
end
|
40
|
-
|
41
|
-
def initialize
|
42
|
-
@gems = []
|
43
|
-
end
|
44
|
-
|
45
|
-
# Receive a call to add a gem to the list
|
46
|
-
def gem(name, options={})
|
47
|
-
data = {}
|
48
|
-
|
49
|
-
# Add new keys from old keys
|
50
|
-
data[:require] = options[:lib] if options[:lib]
|
51
|
-
data[:source] = options[:source] if options[:source]
|
52
|
-
|
53
|
-
version = options[:version]
|
54
|
-
@gems << [name, version, data]
|
55
|
-
end
|
56
|
-
|
57
|
-
# Generate the Gemfile output
|
58
|
-
def output
|
59
|
-
# Generic preamble, taken from Yehuda Katz's blog
|
60
|
-
preamble = <<STR
|
61
|
-
# Edit this Gemfile to bundle your application's dependencies.
|
62
|
-
# This preamble is the current preamble for Rails 3 apps; edit as needed.
|
63
|
-
source 'http://rubygems.org'
|
64
|
-
|
65
|
-
gem 'rails', '3.0.6'
|
66
|
-
|
67
|
-
STR
|
68
|
-
preamble + generate_upgraded_code
|
69
|
-
end
|
70
|
-
|
71
|
-
# Get Gemfile call for all the gems
|
72
|
-
def generate_upgraded_code
|
73
|
-
code = @gems.map do |name, version, data|
|
74
|
-
version_string = (version ? "'#{version}'" : nil)
|
75
|
-
source = data.delete(:source)
|
76
|
-
|
77
|
-
data_string = nil
|
78
|
-
unless data.empty?
|
79
|
-
data_string = data.to_a.map {|k, v| ":#{k} => '#{v}'"}.join(", ")
|
80
|
-
end
|
81
|
-
|
82
|
-
# If we have a source, generate a call to +source+ then output the
|
83
|
-
# gem call. Otherwise, just generate the gem requirement.
|
84
|
-
if source
|
85
|
-
str = ["'#{name}'", version_string, data_string].compact.join(", ")
|
86
|
-
"source '#{source}'\ngem #{str}"
|
87
|
-
else
|
88
|
-
str = ["'#{name}'", version_string, data_string].compact.join(", ")
|
89
|
-
"gem #{str}"
|
90
|
-
end
|
91
|
-
end.join("\n")
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/string/inflections'
|
2
|
-
|
3
|
-
module Rails
|
4
|
-
module Upgrading
|
5
|
-
class NewConfigurationGenerator
|
6
|
-
def generate_new_configurations
|
7
|
-
if has_environment?
|
8
|
-
generate_new_application_rb
|
9
|
-
else
|
10
|
-
raise FileNotFoundError, "Can't find environment.rb [config/environment.rb]!"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def has_environment?
|
15
|
-
File.exists?("config/environment.rb")
|
16
|
-
end
|
17
|
-
|
18
|
-
def environment_code
|
19
|
-
File.open("config/environment.rb").read
|
20
|
-
end
|
21
|
-
|
22
|
-
def generate_new_application_rb
|
23
|
-
environment_file = environment_code
|
24
|
-
|
25
|
-
initializer_code = ""
|
26
|
-
if matches = environment_file.match(/Rails\:\:Initializer\.run do \|config\|\n(.*)\nend/m)
|
27
|
-
initializer_code = matches[1]
|
28
|
-
else
|
29
|
-
raise "There doesn't seem to be a real environment.rb in your app. Are you sure config/environment.rb has the right contents?"
|
30
|
-
end
|
31
|
-
|
32
|
-
frame = "# Put this in config/application.rb
|
33
|
-
require File.expand_path('../boot', __FILE__)
|
34
|
-
|
35
|
-
require 'rails/all'
|
36
|
-
|
37
|
-
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
38
|
-
|
39
|
-
module #{app_name.classify}
|
40
|
-
class Application < Rails::Application
|
41
|
-
config.autoload_paths += [config.root.join('lib')]
|
42
|
-
config.encoding = 'utf-8'
|
43
|
-
%s
|
44
|
-
end
|
45
|
-
end"
|
46
|
-
|
47
|
-
frame % [indent(initializer_code)]
|
48
|
-
end
|
49
|
-
|
50
|
-
def indent(text)
|
51
|
-
text.split("\n").map {|l| " #{l}"}.join("\n")
|
52
|
-
end
|
53
|
-
|
54
|
-
def app_name
|
55
|
-
File.basename(Dir.pwd)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
File without changes
|