Class: DuckMap::List
- Inherits:
-
Object
- Object
- DuckMap::List
- Defined in:
- lib/duck_map/list.rb
Overview
Lists all of the sitemaps defined in config/routes.rb
Instance Method Summary collapse
Instance Method Details
#build(options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/duck_map/list.rb', line 8 def build( = {}) key = [:key].blank? ? :all : [:key].to_s.downcase.to_sym verbose = .has_key?(:verbose) ? true : false verbose = key.eql?(:all) ? verbose : true puts "Searching for route: #{key}" routes = [] if key.eql?(:all) routes = Rails.application.routes.sitemap_routes_only else route = Rails.application.routes.find_route_via_name("#{key}_sitemap") if route.blank? puts "Unable to find route: #{key}" else routes.push(route) end end if routes.length > 0 puts "\r\n\r\nSitemap routes" puts %(#{"route name".ljust(40)} controller_name#action_name) puts %(#{"".ljust(40)} path) puts "---------------------------------------------------------------------------------------------------------------" routes.each do |route| default_route = !route.name.blank? && route.name.to_sym.eql?(:sitemap_sitemap) ? " (DEFAULT)" : "" puts %(\r\n#{(route.name.blank? ? "".ljust(40) : "#{route.name}#{default_route}".ljust(40))} #{route.controller_name}##{route.action_name}) puts %(#{"".ljust(40)} #{route.path.spec}) if verbose sitemap_routes = Rails.application.routes.sitemap_routes(route) if sitemap_routes.length > 0 puts %(#{"".ljust(5)} --------------------------------------------------------------) sitemap_routes.each do |sitemap_route| puts %(#{"".ljust(5)} #{(sitemap_route.name.blank? ? "".ljust(34) : "#{sitemap_route.name}".ljust(34))} #{sitemap_route.controller_name}##{sitemap_route.action_name}) puts %(#{"".ljust(40)} #{sitemap_route.path.spec}) end else puts %(#{"".ljust(10)} No routes) puts %(#{"".ljust(10)} ----------------------------------------------) end end end else puts "Sorry, no routes found..." end end |