Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed max_widths to a hash

  • Loading branch information...
commit e9287f38821cfad99e590a5f60ed3b89c4a1ceda 1 parent 2ba3404
@nicooga authored
Showing with 11 additions and 9 deletions.
  1. +11 −9 lib/color_routes/rails/tasks/color_routes.rake
View
20 lib/color_routes/rails/tasks/color_routes.rake
@@ -16,19 +16,21 @@ task :color_routes => :environment do
all_routes.reject! { |route| route.verb.nil? || route.path.spec.to_s == '/assets' }
all_routes.select! { |route| ENV['CONTROLLER'].nil? || route.defaults[:controller].to_s == ENV['CONTROLLER'] }
- names_max_width = all_routes.map { |route| route.name.to_s.length }.max
- verbs_max_width = 6
- paths_max_width = all_routes.map { |route| route.path.spec.to_s.length }.max
- controllers_max_width = all_routes.map { |route| route.defaults[:controller].to_s.length }.max
- actions_max_width = all_routes.map { |route| route.defaults[:action].to_s.length }.max
+ max_widths = {
+ names: (all_routes.map { |route| route.name.to_s.length }.max),
+ verbs: (6),
+ paths: (all_routes.map { |route| route.path.spec.to_s.length }.max),
+ controllers: (all_routes.map { |route| route.defaults[:controller].to_s.length }.max),
+ actions: (all_routes.map { |route| route.defaults[:action].to_s.length }.max)
+ }
all_routes.group_by { |route| route.defaults[:controller] }.each_value do |group|
puts EMK + "\nCONTROLLER: " + EMW + group.first.defaults[:controller].to_s + NOCOLOR
group.each do |route|
- name = EMC + route.name.to_s.rjust(names_max_width) + NOCOLOR
- verb = EMY + route.verb.inspect.gsub(/^.{2}|.{2}$/, "").center(verbs_max_width) + NOCOLOR
- path = EMR + route.path.spec.to_s.ljust(paths_max_width).gsub(/\.?:\w+/){|s|EMB + s + EMR} + NOCOLOR
- action = EMW + route.defaults[:action].to_s.ljust(actions_max_width) + NOCOLOR
+ name = EMC + route.name.to_s.rjust(max_widths[:names]) + NOCOLOR
+ verb = EMY + route.verb.inspect.gsub(/^.{2}|.{2}$/, "").center(max_widths[:verbs]) + NOCOLOR
+ path = EMR + route.path.spec.to_s.ljust(max_widths[:paths]).gsub(/\.?:\w+/){|s|EMB + s + EMR} + NOCOLOR
+ action = EMW + route.defaults[:action].to_s.ljust(max_widths[:actions]) + NOCOLOR
puts "#{name} | #{verb} | #{path} | #{action}"
end
Please sign in to comment.
Something went wrong with that request. Please try again.