Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure we are not calling length on nil.
- Loading branch information
Showing
1 changed file
with
4 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,8 +1,7 @@ | |||
desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.' | desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.' | ||
task :routes => :environment do | task :routes => :environment do | ||
Rails.application.reload_routes! | Rails.application.reload_routes! | ||
|
all_routes = Rails.application.routes.routes | ||
all_routes = Rails.application.routes.routes | |||
|
|
||
if ENV['CONTROLLER'] | if ENV['CONTROLLER'] | ||
all_routes = all_routes.select{ |route| route.defaults[:controller] == ENV['CONTROLLER'] } | all_routes = all_routes.select{ |route| route.defaults[:controller] == ENV['CONTROLLER'] } | ||
|
@@ -19,9 +18,9 @@ task :routes => :environment do | ||
|
|
||
routes.reject! { |r| r[:path] =~ %r{/rails/info/properties} } # Skip the route if it's internal info route | routes.reject! { |r| r[:path] =~ %r{/rails/info/properties} } # Skip the route if it's internal info route | ||
|
|
||
name_width = routes.map{ |r| r[:name] }.map(&:length).max | name_width = routes.map{ |r| r[:name].length if r[:name] }.max | ||
verb_width = routes.map{ |r| r[:verb] }.map(&:length).max | verb_width = routes.map{ |r| r[:verb].length if r[:verb] }.max | ||
path_width = routes.map{ |r| r[:path] }.map(&:length).max | path_width = routes.map{ |r| r[:path].length if r[:path] }.max | ||
|
|
||
routes.each do |r| | routes.each do |r| | ||
puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}" | puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}" | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ncook
|
|||
|
Surely the references to r[:name], r[:verb] and r[;path] need to be protected here too. rjust is not a method on nil.