Class: RailsUpgrade::Upgraders::Check
- Inherits:
-
Object
- Object
- RailsUpgrade::Upgraders::Check
- Defined in:
- lib/rails-upgrade/upgraders/check.rb
Instance Method Summary collapse
- #check(args) ⇒ Object (also: #upgrade!)
- #check_ar_methods ⇒ Object
- #check_environment ⇒ Object
- #check_gems ⇒ Object
- #check_generators ⇒ Object
- #check_mailers ⇒ Object
- #check_plugins ⇒ Object
- #check_routes ⇒ Object
-
#initialize ⇒ Check
constructor
A new instance of Check.
Constructor Details
#initialize ⇒ Check
Returns a new instance of Check.
7 8 9 10 11 |
# File 'lib/rails-upgrade/upgraders/check.rb', line 7 def initialize @issues = [] raise NotInRailsAppError unless File.exist?("config/environment.rb") end |
Instance Method Details
#check(args) ⇒ Object Also known as: upgrade!
13 14 15 16 17 |
# File 'lib/rails-upgrade/upgraders/check.rb', line 13 def check(args) the_methods = (self.public_methods - Object.methods) - ["upgrade!", "check"] the_methods.each {|m| send m } end |
#check_ar_methods ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rails-upgrade/upgraders/check.rb', line 20 def check_ar_methods files = [] ["find(:all", "find(:first", ":conditions =>", ":joins =>"].each do |v| lines = grep_for(v, "app/models/*") files += extract_filenames(lines) || [] end unless files.empty? alert( "Soon-to-be-deprecated ActiveRecord calls", "Methods such as find(:all), find(:first), finds with conditions, and the :joins option will soon be deprecated.", "http://m.onkey.org/2010/1/22/active-record-query-interface", files ) end lines = grep_for("named_scope", "app/models/*") files = extract_filenames(lines) if files alert( "named_scope is now just scope", "The named_scope method has been renamed to just scope.", "http://github.com/rails/rails/commit/d60bb0a9e4be2ac0a9de9a69041a4ddc2e0cc914", files ) end end |
#check_environment ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rails-upgrade/upgraders/check.rb', line 66 def check_environment unless File.exist?("config/application.rb") alert( "New file needed: config/application.rb", "You need to add a config/application.rb.", "http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade", "config/application.rb" ) end lines = grep_for("config.", "config/environment.rb") files = extract_filenames(lines) if files alert( "Old environment.rb", "environment.rb doesn't do what it used to; you'll need to move some of that into application.rb.", "http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade", "config/environment.rb" ) end end |
#check_gems ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rails-upgrade/upgraders/check.rb', line 89 def check_gems lines = grep_for("config.gem ", "config/*.rb") files = extract_filenames(lines) if files alert( "Old gem bundling (config.gems)", "The old way of bundling is gone now. You need a Gemfile for bundler.", "http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade", files ) end end |
#check_generators ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/rails-upgrade/upgraders/check.rb', line 132 def check_generators generators = Dir.glob("vendor/plugins/**/generators/**/*.rb") unless generators.empty? lines = grep_for("def manifest", generators.join(" ")) files = extract_filenames(lines) if files alert( "Old Rails generator API", "A plugin in the app is using the old generator API (a new one may be available at http://github.com/trydionel/rails3-generators).", "http://blog.plataformatec.com.br/2010/01/discovering-rails-3-generators/", files ) end end end |
#check_mailers ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/rails-upgrade/upgraders/check.rb', line 103 def check_mailers lines = grep_for("deliver_", "app/models/* app/controllers/* app/observers/*") files = extract_filenames(lines) if files alert( "Deprecated ActionMailer API", "You're using the old ActionMailer API to send e-mails in a controller, model, or observer.", "http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3", files ) end files = [] ["recipients ", "attachment ", "subject ", "from "].each do |v| lines = grep_for(v, "app/models/*") files += extract_filenames(lines) || [] end unless files.empty? alert( "Old ActionMailer class API", "You're using the old API in a mailer class.", "http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3", files ) end end |
#check_plugins ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/rails-upgrade/upgraders/check.rb', line 150 def check_plugins # This list is off the wiki; will need to be updated often, esp. since RSpec is working on it bad_plugins = ["rspec", "rspec-rails", "hoptoad", "authlogic", "nifty-generators", "restful_authentication", "searchlogic", "cucumber", "cucumber-rails"] bad_plugins = bad_plugins.map {|p| p if File.exist?("vendor/plugins/#{p}") || !Dir.glob("vendor/gems/#{p}-*").empty?}.compact unless bad_plugins.empty? alert( "Known broken plugins", "At least one plugin in your app is broken (according to the wiki). Most of project maintainers are rapidly working towards compatability, but do be aware you may encounter issues.", "http://wiki.rubyonrails.org/rails/version3/plugins_and_gems", bad_plugins ) end end |
#check_routes ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rails-upgrade/upgraders/check.rb', line 49 def check_routes files = [] ["map.", "ActionController::Routing::Routes", ".resources"].each do |v| lines = grep_for(v, "config/routes.rb") files += extract_filenames(lines) || [] end unless files.empty? alert( "Old router API", "The router API has totally changed.", "http://yehudakatz.com/2009/12/26/the-rails-3-router-rack-it-up/", "config/routes.rb" ) end end |