class RoutingReport::Report

Attributes

base_class[R]
routes[R]

Public Class Methods

new(base_class: Object, routes: []) click to toggle source
# File lib/routing_report/report.rb, line 5
def initialize(base_class: Object, routes: [])
  @base_class, @routes = base_class, routes
end

Public Instance Methods

actions_without_routes() click to toggle source
# File lib/routing_report/report.rb, line 39
def actions_without_routes
  base_class.descendants.each_with_object([]) do |controller_class, accum|
    controller_name = controller_class.name.underscore.match(/\A(.*)_controller\z/)[1]

    controller_class.public_instance_methods(false).each do |method|
      unless routes.any? { |r| r.defaults[:controller] == controller_name && r.defaults[:action] == method.to_s }
        accum << "#{controller_name}##{method.to_s}"
      end
    end
  end.sort
end
print(to: STDOUT) click to toggle source
routes_without_actions() click to toggle source
# File lib/routing_report/report.rb, line 14
def routes_without_actions
  routes.each_with_object([]) do |route, accum|
    controller_name = route.defaults[:controller]
    action_name = route.defaults[:action]

    if controller_name && action_name
      begin
        controller = "#{controller_name}_controller".classify.constantize
      rescue NameError
        accum << "#{controller_name}##{action_name}"
        next
      end

      # get all superclasses that descend from ActionController::Base
      # this allows us to avoid false positives when routes are fulfilled by
      # actions in a superclass:
      matching_controllers = controller.ancestors.select { |c| c < base_class }

      unless matching_controllers.any? { |c| c.public_instance_methods.include?(action_name.to_sym) }
        accum << "#{controller_name}##{action_name}"
      end
    end
  end.sort
end

Private Instance Methods

print_table(title, rows, to) click to toggle source