class RailsRouteChecker::Runner
Public Class Methods
new(**opts)
click to toggle source
# File lib/rails-route-checker/runner.rb, line 5 def initialize(**opts) @options = { ignored_controllers: [], ignored_paths: [], ignored_path_whitelist: {} } @options.merge!(RailsRouteChecker::ConfigFile.new(opts[:config_file]).config) if opts[:config_file] @options.merge!(opts) end
Public Instance Methods
issues()
click to toggle source
# File lib/rails-route-checker/runner.rb, line 11 def issues @issues ||= { missing_actions: app_interface.routes_without_actions, missing_routes: app_interface.undefined_path_method_calls } end
issues?()
click to toggle source
# File lib/rails-route-checker/runner.rb, line 18 def issues? issues.values.flatten(1).count.positive? end
output()
click to toggle source
# File lib/rails-route-checker/runner.rb, line 22 def output output_lines = [] output_lines += missing_actions_output if issues[:missing_actions].any? if issues[:missing_routes].any? output_lines << "\n" if output_lines.any? output_lines += missing_routes_output end output_lines = ['All good in the hood'] if output_lines.empty? output_lines.join("\n") end
Private Instance Methods
app_interface()
click to toggle source
# File lib/rails-route-checker/runner.rb, line 35 def app_interface @app_interface ||= RailsRouteChecker::AppInterface.new(**@options) end
missing_actions_output()
click to toggle source
# File lib/rails-route-checker/runner.rb, line 39 def missing_actions_output [ "The following #{issues[:missing_actions].count} routes are defined, " \ 'but have no corresponding controller action.', 'If you have recently added a route to routes.rb, make sure a matching action exists in the controller.', 'If you have recently removed a controller action, also remove the route in routes.rb.', *issues[:missing_actions].map { |r| " - #{r[:controller]}##{r[:action]}" } ] end
missing_routes_output()
click to toggle source
# File lib/rails-route-checker/runner.rb, line 49 def missing_routes_output [ "The following #{issues[:missing_routes].count} url and path methods don't correspond to any route.", *issues[:missing_routes].map { |line| " - #{line[:file]}:#{line[:line]} - call to #{line[:method]}" } ] end