Skip to content
This repository
Browse code

migrated to airbrake from hoptoad

cleaned up data importing tasks
removed some deprecated stuff
  • Loading branch information...
commit c6ce544b56ee576fda52f0fdbf92d7417174030b 1 parent 6dfaa81
aross authored February 13, 2012

Showing 29 changed files with 77 additions and 1,794 deletions. Show diff stats Hide diff stats

  1. 2  Gemfile
  2. 8  Gemfile.lock
  3. 30  README.md
  4. 6  bin/daily/daily_parse_people.rb
  5. 37  bin/daily/govtrack-rsync.sh
  6. 2  config/api_keys.yml
  7. 11  config/application_settings.yml
  8. 11  config/deploy.rb
  9. 5  config/initializers/airbrake.rb
  10. 3  config/initializers/hoptoad.rb
  11. 8  lib/tasks/daily.rake
  12. 25  lib/tasks/hoptoad_notifier_tasks.rake
  13. 0  rails_upgrade.rb b/vendor/plugins/rails_upgrade/lib/rails_upgrade.rb
  14. 20  vendor/plugins/rails_upgrade/MIT-LICENSE
  15. 20  vendor/plugins/rails_upgrade/README
  16. 22  vendor/plugins/rails_upgrade/Rakefile
  17. 2  vendor/plugins/rails_upgrade/init.rb
  18. 38  vendor/plugins/rails_upgrade/install.rb
  19. 472  vendor/plugins/rails_upgrade/lib/application_checker.rb
  20. 95  vendor/plugins/rails_upgrade/lib/gemfile_generator.rb
  21. 51  vendor/plugins/rails_upgrade/lib/new_configuration_generator.rb
  22. 349  vendor/plugins/rails_upgrade/lib/routes_upgrader.rb
  23. 78  vendor/plugins/rails_upgrade/lib/tasks/rails_upgrade_tasks.rake
  24. 293  vendor/plugins/rails_upgrade/test/application_checker_test.rb
  25. 72  vendor/plugins/rails_upgrade/test/gemfile_generator_test.rb
  26. 63  vendor/plugins/rails_upgrade/test/new_configuration_generator_test.rb
  27. 142  vendor/plugins/rails_upgrade/test/routes_upgrader_test.rb
  28. 5  vendor/plugins/rails_upgrade/test/test_helper.rb
  29. 1  vendor/plugins/rails_upgrade/uninstall.rb
2  Gemfile
@@ -40,7 +40,7 @@ gem 'paperclip'
40 40
 
41 41
 
42 42
 # notifier for production errors
43  
-gem "hoptoad_notifier"
  43
+gem "airbrake"
44 44
 gem "xray", :require => "xray/thread_dump_signal_handler"
45 45
 
46 46
 # OpenID 
8  Gemfile.lock
@@ -56,6 +56,9 @@ GEM
56 56
       activesupport (= 3.0.7)
57 57
     activesupport (3.0.7)
58 58
     addressable (2.2.6)
  59
+    airbrake (3.0.9)
  60
+      activesupport
  61
+      builder
59 62
     arel (2.0.10)
60 63
     autotest (4.4.6)
61 64
       ZenTest (>= 4.4.1)
@@ -141,9 +144,6 @@ GEM
141 144
       railties (~> 3.0)
142 145
     hashie (1.1.0)
143 146
     highline (1.6.2)
144  
-    hoptoad_notifier (2.4.11)
145  
-      activesupport
146  
-      builder
147 147
     hpricot (0.8.4)
148 148
     htmlentities (4.3.0)
149 149
     httmultiparty (0.3.6)
@@ -281,6 +281,7 @@ PLATFORMS
281 281
 DEPENDENCIES
282 282
   RedCloth
283 283
   acts-as-taggable-on!
  284
+  airbrake
284 285
   autotest
285 286
   bluecloth
286 287
   capistrano
@@ -299,7 +300,6 @@ DEPENDENCIES
299 300
   guard-livereload
300 301
   haml
301 302
   haml-rails
302  
-  hoptoad_notifier
303 303
   hpricot
304 304
   htmlentities
305 305
   jammit
30  README.md
Source Rendered
@@ -34,34 +34,44 @@ Follow the instructions after the packages install for initializing your databas
34 34
 
35 35
 Install the bundle:
36 36
 
37  
-<pre>
38 37
 <code>
39 38
 [sudo] gem install bundler
40 39
 bundle install
41 40
 </code>
42  
-</pre>
43 41
 
44 42
 __Note for OS X:__ *You may need to specify additional compile options for your gems. Try: `ARCHFLAGS="-arch x86_64" bundle install`
45 43
 
46 44
 ### B. Database setup
47 45
 
48 46
 Running the following commands will create an 'opencongress' user and empty databases for the three environments (test, development, production).  The migration command will populate the development database with an empty schema.
49  
-<pre>
  47
+
50 48
 <code>
51 49
 rake db:init
52 50
 rake db:migrate
53 51
 </code>
54  
-</pre>
55 52
 
56  
-### C. Data (optional)
  53
+### C. Solr (optional, recommended)
57 54
 
58  
-We are developing a process to quickly import some real legislative data.  Coming soon.
59  
-	
60  
-### D. Starting the server
61  
-   
62  
-OpenCongress uses Solr to store some data.  The following command is not required, but some pages will break if Solr is not running:
  55
+OpenCongress uses Solr to store some data.  Running Solr is not required to run the web server, but some pages will break if Solr is not running.  If you are going to import data, running solr is required or you will encounter errors.
  56
+
  57
+You can run Solr with the following command (usually in the background and/or in a separate window):
63 58
 
64 59
 	rake solr:start
  60
+	
  61
+	
  62
+### D. Legislative Data (optional)
  63
+
  64
+See note above about running Solr: it is required for importing data.
  65
+
  66
+To import legislative data into your database, run the following command:
  67
+	
  68
+	rake update:govtrack
  69
+
  70
+This will download data files from [Govtrack](http://govtrack.us) and import them into your database.  The default location for storage of the data files is `/tmp/opencongress_data` but you can change this by editing `config/application_settings.yml`.  This task will import ALL of the data for the current session of Congress: it will take a long time and occupy a LOT of space on your filesystem!  Keep this in mind before importing the data! 
  71
+	
  72
+### E. Starting the server
  73
+   
  74
+See note above about running Solr: it is not required, but recommended.
65 75
 
66 76
 To start the webserver:
67 77
 
6  bin/daily/daily_parse_people.rb
@@ -53,6 +53,8 @@ def tag_end(name)
53 53
   end
54 54
 
55 55
   def make_person(attrs)
  56
+    
  57
+    
56 58
     id = attrs['id'].to_i
57 59
     arr = @people[id]
58 60
     @person = arr[0] unless arr.nil?
@@ -92,6 +94,8 @@ def make_person(attrs)
92 94
     @person.district = attrs['district']
93 95
     @person.state = attrs['state']
94 96
     @person.email = attrs['email']
  97
+    
  98
+    puts "Legislator: #{@person.name}, birthday: #{@person.birthday}"
95 99
   end
96 100
 
97 101
   def make_role(as)
@@ -154,7 +158,7 @@ def method_missing(*args)
154 158
   end
155 159
 end
156 160
 
157  
-puts "people parsed"
  161
+puts "Parsing All Legislators from govtrack file..."
158 162
 
159 163
 Person.transaction {
160 164
   source = File.open(Settings.govtrack_data_path + "/#{Settings.default_congress}/../people.xml")
37  bin/daily/govtrack-rsync.sh
@@ -3,24 +3,37 @@ if [ -d "$1" ]
3 3
   then
4 4
   data=$1
5 5
 else
6  
-  echo 'data dir not found! fix DATA_PATH in your environment file'
7  
-  exit
  6
+  echo 'data dir not found! trying to create file...'
  7
+  mkdir -p $1
  8
+
  9
+  if [ ! -d "$1" ]
  10
+  then
  11
+    echo 'could not create $1!'
  12
+    exit
  13
+  fi
  14
+
  15
+  data=$1
  16
+fi
  17
+
  18
+if [ ! -d "$data/govtrack" ]
  19
+then
  20
+  mkdir -p $data/govtrack
8 21
 fi
9 22
 
10  
-if [ ! -d "$data/govtrack/log" ]
  23
+if [ ! -d "$data/govtrack/bills.text" ]
11 24
 then
12  
-  mkdir -p $data/govtrack/log
  25
+  mkdir -p $data/govtrack/bills.text
13 26
 fi
14 27
 
15  
-if [ ! -e "$data/govtrack/log/govtrack-rsync.log" ]
  28
+if [ ! -d "$data/govtrack/bills.text.cmp" ]
16 29
 then
17  
-  touch $data/govtrack/log/govtrack-rsync.log
  30
+  mkdir -p $data/govtrack/bills.text.cmp
18 31
 fi
19 32
 
20  
-cd $data/govtrack
  33
+cd $data
21 34
 
22  
-echo "\n\nrsyncing govtrack at `date`" >> log/govtrack-rsync.log
23  
-rsync -avz govtrack.us::govtrackdata/us/people.xml . >> log/govtrack-rsync.log
24  
-rsync -avz --exclude '*.pdf' --exclude '*.png' govtrack.us::govtrackdata/us/112 . >> log/govtrack-rsync.log
25  
-rsync -avz --exclude '*.pdf' govtrack.us::govtrackdata/us/bills.text/112 ./bills.text/ >> log/govtrack-rsync.log
26  
-rsync -avz govtrack.us::govtrackdata/us/bills.text.cmp/112 ./bills.text.cmp/ >> log/govtrack-rsync.log
  35
+echo "\n\nrsyncing govtrack at `date`"
  36
+rsync -avz govtrack.us::govtrackdata/us/people.xml ./govtrack/
  37
+rsync -avz --exclude '*.pdf' --exclude '*.png' govtrack.us::govtrackdata/us/112 ./govtrack/
  38
+rsync -avz --exclude '*.pdf' govtrack.us::govtrackdata/us/bills.text/112 ./govtrack/bills.text/ 
  39
+rsync -avz govtrack.us::govtrackdata/us/bills.text.cmp/112 ./govtrack/bills.text.cmp/
2  config/api_keys.yml
@@ -15,7 +15,7 @@ defaults: &defaults
15 15
   civicrm_user_key: xxx
16 16
   project_vote_smart: xxx
17 17
   google_maps: xxx
18  
-  hoptoad: xxx
  18
+  airbrake: xxx
19 19
   bitly: xxx
20 20
   aws_access_key_id: xxx
21 21
   aws_secret_access_key: xxx
11  config/application_settings.yml
@@ -41,11 +41,12 @@ defaults: &defaults
41 41
 development:
42 42
   <<: *defaults
43 43
 
44  
-  govtrack_data_path: /Users/aross/pcf-work/govtrack_data/us
45  
-  govtrack_billtext_path: /Users/aross/pcf-work/govtrack_data/us/bills.text
46  
-  govtrack_billtext_diff_path: /Users/aross/pcf-work/govtrack_data/us/bills.text.cmp
47  
-  oc_billtext_path: /Users/aross/pcf-work/oc_billtext
48  
-  committee_reports_path: /Users/aross/pcf-work/committee_reports
  44
+  data_path: /tmp/opencongress_data
  45
+  govtrack_data_path: /tmp/opencongress_data/govtrack
  46
+  govtrack_billtext_path: /tmp/opencongress_data/govtrack/bills.text
  47
+  govtrack_billtext_diff_path: /tmp/opencongress_data/govtrack/bills.text.cmp
  48
+  oc_billtext_path: /tmp/opencongress_data/opencongress/bills.text
  49
+  committee_reports_path: /tmp/opencongress_data/committee_reports
49 50
   
50 51
   group_images_path: <%= Rails.root %>/public/system/group_images
51 52
   notebook_files_path: <%= Rails.root %>/public/system/notebook_files
11  config/deploy.rb
@@ -51,7 +51,7 @@
51 51
     run "ln -s #{deploy_to}/#{shared_dir}/files/oc_whats.flv #{current_release}/public/oc_whats.flv"
52 52
     run "ln -s #{deploy_to}/#{shared_dir}/files/screencast.mp4 #{current_release}/public/screencast.mp4"
53 53
     run "ln -s #{deploy_to}/#{shared_dir}/files/facebook.yml #{current_release}/config/"
54  
-#    sudo "chown -R mongrel:admins #{current_release}"
  54
+    #    sudo "chown -R mongrel:admins #{current_release}"
55 55
   end
56 56
 
57 57
   desc "Compile CSS & JS for public/assets/ (see assets.yml)"
@@ -80,9 +80,6 @@
80 80
 after "deploy:update_code", "deploy:jammit"
81 81
 
82 82
 
83  
-# HopToad notification.
84  
-Dir[File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'hoptoad_notifier-*')].each do |vendored_notifier|
85  
-  $: << File.join(vendored_notifier, 'lib')
86  
-end
87  
-
88  
-require 'hoptoad_notifier/capistrano'
  83
+# Airbrake put the following in; necessary?
  84
+#require './config/boot'
  85
+require 'airbrake/capistrano'
5  config/initializers/airbrake.rb
... ...
@@ -0,0 +1,5 @@
  1
+require 'config/initializers/api_keys'
  2
+
  3
+Airbrake.configure do |config|
  4
+  config.api_key = ApiKeys.airbrake
  5
+end
3  config/initializers/hoptoad.rb
... ...
@@ -1,3 +0,0 @@
1  
-HoptoadNotifier.configure do |config|
2  
-  config.api_key = ApiKeys.hoptoad
3  
-end
8  lib/tasks/daily.rake
@@ -62,9 +62,13 @@ namespace :update do
62 62
 
63 63
   task :people => :environment do
64 64
     begin
65  
-      data = IO.popen("sha1sum -c /tmp/people.sha1").read
  65
+      begin
  66
+        data = IO.popen("sha1sum -c /tmp/people.sha1").read
  67
+      rescue
  68
+        data = "XXX"
  69
+      end
  70
+      
66 71
       unless data.match(/OK\n$/)
67  
-        system "sha1sum #{Settings.data_path}/govtrack/people.xml >/tmp/people.sha1"
68 72
         Person.transaction {
69 73
           load 'bin/daily/daily_parse_people.rb'
70 74
         }
25  lib/tasks/hoptoad_notifier_tasks.rake
... ...
@@ -1,25 +0,0 @@
1  
-# Don't load anything when running the gems:* tasks.
2  
-# Otherwise, hoptoad_notifier will be considered a framework gem.
3  
-# https://thoughtbot.lighthouseapp.com/projects/14221/tickets/629
4  
-unless ARGV.any? {|a| a =~ /^gems/} 
5  
-
6  
-  Dir[File.join(Rails.root.to_s, 'vendor', 'gems', 'hoptoad_notifier-*')].each do |vendored_notifier|
7  
-    $: << File.join(vendored_notifier, 'lib')
8  
-  end
9  
-
10  
-  begin
11  
-    require 'hoptoad_notifier/tasks'
12  
-  rescue LoadError => exception
13  
-    namespace :hoptoad do
14  
-      %w(deploy test log_stdout).each do |task_name|
15  
-        desc "Missing dependency for hoptoad:#{task_name}"
16  
-        task task_name do
17  
-          $stderr.puts "Failed to run hoptoad:#{task_name} because of missing dependency."
18  
-          $stderr.puts "You probably need to run `rake gems:install` to install the hoptoad_notifier gem"
19  
-          abort exception.inspect
20  
-        end
21  
-      end
22  
-    end
23  
-  end
24  
-
25  
-end
0  rails_upgrade.rb b/vendor/plugins/rails_upgrade/lib/rails_upgrade.rb
No changes.
20  vendor/plugins/rails_upgrade/MIT-LICENSE
... ...
@@ -1,20 +0,0 @@
1  
-Copyright (c) 2010 Jeremy McAnally
2  
-
3  
-Permission is hereby granted, free of charge, to any person obtaining
4  
-a copy of this software and associated documentation files (the
5  
-"Software"), to deal in the Software without restriction, including
6  
-without limitation the rights to use, copy, modify, merge, publish,
7  
-distribute, sublicense, and/or sell copies of the Software, and to
8  
-permit persons to whom the Software is furnished to do so, subject to
9  
-the following conditions:
10  
-
11  
-The above copyright notice and this permission notice shall be
12  
-included in all copies or substantial portions of the Software.
13  
-
14  
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17  
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18  
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19  
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20  
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20  vendor/plugins/rails_upgrade/README
... ...
@@ -1,20 +0,0 @@
1  
-= rails-upgrade
2  
-
3  
-A simple battery of scripts for upgrading Rails app/checking them for required updates.  This application should work on Rails 2.x and 3.0, with a focus on upgrading to 3.0.
4  
-
5  
-== Usage
6  
-
7  
-    # Check your app for required upgrades
8  
-    rake rails:upgrade:check
9  
-    
10  
-    # Backup your likely modified files that might be overwritten by the generator
11  
-    rake rails:upgrade:backup
12  
-    
13  
-    # Generate a new route file
14  
-    rake rails:upgrade:routes
15  
-    
16  
-    # Generate a Gemfile from your config.gem directives
17  
-    rake rails:upgrade:gems
18  
-
19  
-    # Generate code for a new config/application.rb from your environment.rb
20  
-    rake rails:upgrade:configuration
22  vendor/plugins/rails_upgrade/Rakefile
... ...
@@ -1,22 +0,0 @@
1  
-require 'rake'
2  
-require 'rake/testtask'
3  
-require 'rake/rdoctask'
4  
-
5  
-desc 'Default: run unit tests.'
6  
-task :default => :test
7  
-
8  
-Rake::TestTask.new do |t|
9  
-  t.libs << 'lib'
10  
-  t.libs << 'test'
11  
-  t.test_files = FileList['test/*_test.rb']
12  
-  t.verbose = true
13  
-end
14  
-
15  
-desc 'Generate documentation for the rails_upgrade plugin.'
16  
-Rake::RDocTask.new(:rdoc) do |rdoc|
17  
-  rdoc.rdoc_dir = 'rdoc'
18  
-  rdoc.title    = 'Rails-upgrade'
19  
-  rdoc.options << '--line-numbers' << '--inline-source'
20  
-  rdoc.rdoc_files.include('README')
21  
-  rdoc.rdoc_files.include('lib/**/*.rb')
22  
-end
2  vendor/plugins/rails_upgrade/init.rb
... ...
@@ -1,2 +0,0 @@
1  
-# Get long stack traces for easier debugging; you'll thank me later.
2  
-Rails.backtrace_cleaner.remove_silencers!
38  vendor/plugins/rails_upgrade/install.rb
... ...
@@ -1,38 +0,0 @@
1  
-puts "Thanks for installing the Rails upgrade plugin.  This is a set of generators and analysis tools to help you upgrade your application to Rails 3.  It consists of three tasks...
2  
-
3  
-To get a feel for what you'll need to change to get your app running, run the application analysis:
4  
-
5  
-    rake rails:upgrade:check
6  
-    
7  
-This should give you an idea of the manual changes that need to be done, but you'll probably want to upgrade some of those automatically.  The fastest way to do this is to run 'rails .', which will simply generate a new app on top of your existing code.  But this generation also has the effect of replacing some existing files, some of which you might not want to replace.  To back those up, first run:
8  
-
9  
-    rake rails:upgrade:backup
10  
-    
11  
-That will backup files you've probably edited that will be replaced in the upgrade; if you finish the upgrade and find that you don't need the old copies, just delete them.  Otherwise, copy their contents back into the new files or run one of the following upgraders...
12  
-
13  
-Routes upgrader
14  
-===============
15  
-
16  
-To generate a new routes file from your existing routes file, simply run the following Rake task:
17  
-
18  
-    rake rails:upgrade:routes
19  
-    
20  
-This will output a new routes file that you can copy and paste or pipe into a new, Rails 3 compatible config/routes.rb.
21  
-
22  
-Gemfile generator
23  
-=================  
24  
-
25  
-Creating a new Gemfile is as simple as running:
26  
-
27  
-    rake rails:upgrade:gems
28  
-    
29  
-This task will extract your config.gem calls and generate code you can put into a bundler compatible Gemfile.
30  
-
31  
-Configuration generator
32  
-=======================
33  
-
34  
-Much of the configuration information that lived in environment.rb now belongs in a new file named config/application.rb; use the following task to generate code you can put into config/application.rb from your existing config/environment.rb:
35  
-
36  
-    rake rails:upgrade:configuration
37  
-
38  
-"
472  vendor/plugins/rails_upgrade/lib/application_checker.rb
... ...
@@ -1,472 +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  
-        if files
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  
-        files = extract_filenames(lines)
177  
-
178  
-        if files
179  
-          alert(
180  
-            "Old gem bundling (config.gems)",
181  
-            "The old way of bundling is gone now.  You need a Gemfile for bundler.",
182  
-            "http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade",
183  
-            files
184  
-          )
185  
-        end
186  
-      end
187  
-
188  
-      # Checks for old mailer syntax in both mailer classes and those
189  
-      # classes utilizing the mailers
190  
-      def check_mailers
191  
-        lines = grep_for("deliver_", "app/models/ #{base_path}app/controllers/ #{base_path}app/observers/")
192  
-        files = extract_filenames(lines)
193  
-
194  
-        if files
195  
-          alert(
196  
-            "Deprecated ActionMailer API",
197  
-            "You're using the old ActionMailer API to send e-mails in a controller, model, or observer.",
198  
-            "http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3",
199  
-            files
200  
-          )
201  
-        end
202  
-
203  
-        files = []
204  
-        ["recipients ", "attachment(?!s) ", "(?<!:)subject ", "(?<!:)from "].each do |v|
205  
-          lines = grep_for_with_perl_regex(v, "app/models/")
206  
-          files += extract_filenames(lines) || []
207  
-        end
208  
-
209  
-        unless files.empty?
210  
-          alert(
211  
-            "Old ActionMailer class API",
212  
-            "You're using the old API in a mailer class.",
213  
-            "http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3",
214  
-            files
215  
-          )
216  
-        end
217  
-      end
218  
-
219  
-      # Checks for old-style generators
220  
-      def check_generators
221  
-        generators = Dir.glob(base_path + "vendor/plugins/**/generators/**/")
222  
-
223  
-        unless generators.empty?
224  
-          files = generators.reject do |g|
225  
-                    grep_for("def manifest", g).empty? 
226  
-                  end.compact
227  
-
228  
-          if !files.empty?
229  
-            alert(
230  
-              "Old Rails generator API",
231  
-              "A plugin in the app is using the old generator API (a new one may be available at http://github.com/trydionel/rails3-generators).",
232  
-              "http://blog.plataformatec.com.br/2010/01/discovering-rails-3-generators/",
233  
-              files
234  
-            )
235  
-          end
236  
-        end
237  
-      end
238  
-
239  
-      # Checks a list of known broken plugins and gems
240  
-      def check_plugins
241  
-        # This list is off the wiki; will need to be updated often, esp. since RSpec is working on it
242  
-        bad_plugins = ["rspec", "rspec-rails", "hoptoad", "authlogic", "nifty-generators",
243  
-           "restful_authentication", "searchlogic", "cucumber", "cucumber-rails", "devise",
244  
-           "inherited_resources"]
245  
-
246  
-        bad_plugins = bad_plugins.map do |p|
247  
-                        p if File.exist?("#{base_path}vendor/plugins/#{p}") || !Dir.glob("#{base_path}vendor/gems/#{p}-*").empty?
248  
-                      end.compact
249  
-
250  
-        unless bad_plugins.empty?
251  
-          alert(
252  
-            "Known broken plugins",
253  
-            "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.",
254  
-            "http://wiki.rubyonrails.org/rails/version3/plugins_and_gems",
255  
-            bad_plugins
256  
-          )
257  
-        end
258  
-      end
259  
-
260  
-      # Checks for old-style ERb helpers
261  
-      def check_old_helpers
262  
-
263  
-        lines = grep_for("<% .*content_tag.* do.*%>", "app/views/**/*")
264  
-        lines += grep_for("<% .*javascript_tag.* do.*%>", "app/views/**/*")
265  
-        lines += grep_for("<% .*form_for.* do.*%>", "app/views/**/*")
266  
-        lines += grep_for("<% .*form_tag.* do.*%>", "app/views/**/*")
267  
-        lines += grep_for("<% .*fields_for.* do.*%>", "app/views/**/*")
268  
-        lines += grep_for("<% .*field_set_tag.* do.*%>", "app/views/**/*")
269  
-        
270  
-        files = extract_filenames(lines)
271  
-
272  
-        if files
273  
-          alert(
274  
-            "Deprecated ERb helper calls",
275  
-            "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.",
276  
-            "http://weblog.rubyonrails.org/",
277  
-            files
278  
-          )
279  
-        end
280  
-      end
281  
-
282  
-      # Checks for old-style AJAX helpers
283  
-      def check_old_ajax_helpers
284  
-        files = []
285  
-        ['link_to_remote','form_remote_tag','remote_form_for'].each do |type|
286  
-          lines = grep_for(type, "app/views/**/*")
287  
-          inner_files = extract_filenames(lines)
288  
-          files += inner_files unless inner_files.nil?
289  
-        end
290  
-
291  
-        unless files.empty?
292  
-          alert(
293  
-            "Deprecated AJAX helper calls",
294  
-            "AJAX javascript helpers have been switched to be unobtrusive and use :remote => true instead of having a seperate function to handle remote requests.",
295  
-            "http://www.themodestrubyist.com/2010/02/24/rails-3-ujs-and-csrf-meta-tags/",
296  
-            files
297  
-          )
298  
-        end
299  
-      end
300  
-
301  
-      # Checks for old cookie secret settings
302  
-      def check_old_cookie_secret
303  
-        lines = grep_for("ActionController::Base.cookie_verifier_secret = ", "config/**/*")
304  
-        files = extract_filenames(lines)
305  
-
306  
-        if files
307  
-          alert(
308  
-            "Deprecated cookie secret setting",
309  
-            "Previously, cookie secret was set directly on ActionController::Base; it's now config.secret_token.",
310  
-            "http://lindsaar.net/2010/4/7/rails_3_session_secret_and_session_store",
311  
-            files
312  
-          )
313  
-        end
314  
-      end
315  
-
316  
-      def check_old_session_secret
317  
-        lines = grep_for("ActionController::Base.session = {", "config/**/*")
318  
-        files = extract_filenames(lines)
319  
-
320  
-        if files
321  
-          alert(
322  
-            "Deprecated session secret setting",
323  
-            "Previously, session secret was set directly on ActionController::Base; it's now config.secret_token.",
324  
-            "http://lindsaar.net/2010/4/7/rails_3_session_secret_and_session_store",
325  
-            files
326  
-          )
327  
-        end
328  
-      end
329  
-
330  
-      # Checks for old session settings
331  
-      def check_old_session_setting
332  
-        lines = grep_for("ActionController::Base.session_store", "config/**/*")
333  
-        files = extract_filenames(lines)
334  
-
335  
-        if files
336  
-          alert(
337  
-            "Old session store setting",
338  
-            "Previously, session store was set directly on ActionController::Base; it's now config.session_store :whatever.",
339  
-            "http://lindsaar.net/2010/4/7/rails_3_session_secret_and_session_store",
340  
-            files
341  
-          )
342  
-        end
343  
-      end
344  
-
345  
-    private
346  
-      def grep_for_with_perl_regex(text, where = "./", double_quote = false)
347  
-        grep_for(text, where, double_quote, true)
348  
-      end
349  
-
350  
-      # Find a string in a set of files; calls +find_with_grep+ and +find_with_rak+
351  
-      # depending on platform.
352  
-      #
353  
-      # TODO: Figure out if this works on Windows.
354  
-      def grep_for(text, where = "./", double_quote = false, perl_regex = false)
355  
-        # If they're on Windows, they probably don't have grep.
356  
-        @probably_has_grep ||= (Config::CONFIG['host_os'].downcase =~ /mswin|windows|mingw/).nil?
357  
-        
358  
-        # protect against double root paths in Rails 3
359  
-        where.gsub!(Regexp.new(base_path),'')
360  
-
361  
-        lines = if @probably_has_grep
362  
-          find_with_grep(text, base_path + where, double_quote, perl_regex)
363  
-        else
364  
-          find_with_rak(text, base_path + where, double_quote)
365  
-        end
366  
-
367  
-        # ignore comments
368  
-        lines.gsub /^(\/[^:]+:)?\s*#.+$/m, ""
369  
-      end
370  
-
371  
-      # Sets a base path for finding files; mostly for testing
372  
-      def base_path
373  
-        Dir.pwd + "/"
374  
-      end
375  
-
376  
-      # Use the grep utility to find a string in a set of files
377  
-      def find_with_grep(text, where, double_quote, perl_regex = false)
378  
-        value = ""
379  
-        # Specifically double quote for finding 'test_help'
380  
-        command = if double_quote
381  
-                    "grep -r #{"-P" if perl_regex} --exclude=\*.svn\* \"#{text}\" #{where}"
382  
-                  else
383  
-                    "grep -r #{"-P" if perl_regex} --exclude=\*.svn\* '#{text}' #{where}"
384  
-                  end
385  
-        
386  
-        Open3.popen3(command) do |stdin, stdout, stderr|
387  
-          value = stdout.read
388  
-        end
389  
-        value
390  
-      end
391  
-
392  
-      # Use the rak gem to grep the files (not yet implemented)
393  
-      def find_with_rak(text, where, double_quote)
394  
-        value = ""
395  
-        Open3.popen3("rak --nogroup -l '#{Regexp.escape(text)}' #{where}") do |stdin, stdout, stderr|
396  
-          value = stdout.read
397  
-        end
398  
-        value
399  
-      end
400  
-
401  
-      # Extract the filenames from the grep output
402  
-      def extract_filenames(output)
403  
-        if @probably_has_grep
404  
-          extract_filenames_from_grep(output)
405  
-        else
406  
-          extract_filenames_from_rak(output)
407  
-        end
408  
-      end
409  
-
410  
-      def extract_filenames_from_grep(output)
411  
-        return nil if output.empty?
412  
-
413  
-        output.split("\n").map do |fn|
414  
-          if m = fn.match(/^(.+?):/)
415  
-            m[1]
416  
-          end
417  
-        end.compact.uniq
418  
-      end
419  
-
420  
-      def extract_filenames_from_rak(output)
421  
-        return nil if output.empty?
422  
-
423  
-        output.split("\n").uniq
424  
-      end
425  
-
426  
-      # Terminal colors, borrowed from Thor
427  
-      CLEAR      = "\e[0m"
428  
-      BOLD       = "\e[1m"
429  
-      RED        = "\e[31m"
430  
-      YELLOW     = "\e[33m"
431  
-      CYAN       = "\e[36m"
432  
-      WHITE      = "\e[37m"
433  
-
434  
-      # Show an upgrade alert to the user
435  
-      def alert(title, text, more_info_url, culprits)
436  
-        if Config::CONFIG['host_os'].downcase =~ /mswin|windows|mingw/
437  
-          basic_alert(title, text, more_info_url, culprits)
438  
-        else
439  
-          color_alert(title, text, more_info_url, culprits)
440  
-        end
441  
-      end
442  
-
443  
-      # Show an upgrade alert to the user.  If we're on Windows, we can't
444  
-      # use terminal colors, hence this method.
445  
-      def basic_alert(title, text, more_info_url, culprits)
446  
-        puts "** " + title
447  
-        puts text
448  
-        puts "More information: #{more_info_url}"
449  
-        puts
450  
-        puts "The culprits: "
451  
-        Array(culprits).each do |c|
452  
-          puts "\t- #{c}"
453  
-        end
454  
-        puts
455  
-      end
456  
-
457  
-      # Show a colorful alert to the user
458  
-      def color_alert(title, text, more_info_url, culprits)
459  
-        puts "#{RED}#{BOLD}#{title}#{CLEAR}"
460  
-        puts "#{WHITE}#{text}"
461  
-        puts "#{BOLD}More information:#{CLEAR} #{CYAN}#{more_info_url}"
462  
-        puts
463  
-        puts "#{WHITE}The culprits: "
464  
-        Array(culprits).each do |c|
465  
-          puts "#{YELLOW}\t- #{c}"
466  
-        end
467  
-      ensure
468  
-        puts "#{CLEAR}"
469  
-      end
470  
-    end
471  
-  end
472  
-end
95  vendor/plugins/rails_upgrade/lib/gemfile_generator.rb
... ...
@@ -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.0.beta3'
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
51  vendor/plugins/rails_upgrade/lib/new_configuration_generator.rb
... ...
@@ -1,51 +0,0 @@
1  
-module Rails
2  
-  module Upgrading
3  
-    class NewConfigurationGenerator
4  
-      def generate_new_configurations
5  
-        if has_environment?
6  
-          generate_new_application_rb
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_new_application_rb
21  
-        environment_file = environment_code
22  
-        
23  
-        initializer_code = ""
24  
-        if matches = environment_file.match(/Rails\:\:Initializer\.run do \|config\|\n(.*)\nend/m)
25  
-          initializer_code = matches[1]
26  
-        else
27  
-          raise "There doesn't seem to be a real environment.rb in your app.  Are you sure config/environment.rb has the right contents?"
28  
-        end
29  
-        
30  
-        frame = "# Put this in config/application.rb
31  
-require File.expand_path('../boot', __FILE__)
32  
-
33  
-module #{app_name.classify}
34  
-  class Application < Rails::Application
35  
-%s
36  
-  end
37  
-end"
38  
-        
39  
-        frame % [indent(initializer_code)]        
40  
-      end
41  
-      
42  
-      def indent(text)
43  
-        text.split("\n").map {|l| "  #{l}"}.join("\n")
44  
-      end