Class: RailsInfo::RoutesPresenter
- Defined in:
- app/presenters/rails_info/routes_presenter.rb
Instance Method Summary collapse
Methods inherited from Presenter
Constructor Details
This class inherits a constructor from RailsInfo::Presenter
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RailsInfo::Presenter
Instance Method Details
#accordion ⇒ Object
2 3 4 5 6 7 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 |
# File 'app/presenters/rails_info/routes_presenter.rb', line 2 def accordion routes = request.env['action_dispatch.routes'].routes.map do |route| { source: (route.verb.respond_to?(:source) ? route.verb.source : route.verb).gsub(/[$^]/, ''), spec: route.path.respond_to?(:spec) ? route.path.spec.to_s : route.path, name: route.name, requirements: route.requirements.inspect } end namespaced_routes = {} routes.each do |route| namespace = '/' unless route[:spec] == namespace spec = route[:spec].split('/') spec.shift namespace = spec.shift end namespaced_routes[namespace] ||= [] namespaced_routes[namespace] << route end content_tag :div, class: 'accordions' do html = '' namespaced_routes.each do |namespace, routes| html += content_tag( :h3, raw(" #{namespace}") ) table = render partial: 'rails_info/routes/table', locals: { routes: routes } html += content_tag :div, raw(table), style: "max-height:300px; overflow: auto" end raw html end end |