class RakeUnusedRoutes

Constants

VERSION

Public Class Methods

actions_from_newrelic(file) click to toggle source
# File lib/rake_unused_routes.rb, line 29
def self.actions_from_newrelic(file)
  new_relic_controller_actions = []
  CSV.foreach(file, :col_sep => ",") do |row|
    if row.first && !['HttpDispatcher','Action'].include?(row.first.chomp) && !row.first.chomp.include?('#(template only)')
      new_relic_controller_actions << row.first.chomp
    end
  end
  new_relic_controller_actions.uniq
end
new(app, used_actions: []) click to toggle source
# File lib/rake_unused_routes.rb, line 13
def initialize app, used_actions: []
  @app = app
  @used_actions = used_actions
end

Public Instance Methods

formatted_unused_routes() click to toggle source
# File lib/rake_unused_routes.rb, line 24
def formatted_unused_routes
  inspector = ActionDispatch::Routing::RoutesInspector.new(unused_routes)
  inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, ENV['CONTROLLER'])
end
unused_routes() click to toggle source
# File lib/rake_unused_routes.rb, line 18
def unused_routes
  routes.reject do |route|
    @used_actions.include?( newrelic_formatting(route) )
  end
end

Private Instance Methods

newrelic_formatting(route) click to toggle source
# File lib/rake_unused_routes.rb, line 41
def newrelic_formatting route
  requirements = route.requirements
  "#{requirements[:controller].camelize}Controller##{requirements[:action]}"
end
routes() click to toggle source
# File lib/rake_unused_routes.rb, line 46
def routes
  @app.routes.routes.select{ |route| route.requirements[:controller] }.
      reject {|r| r.requirements[:controller].starts_with? 'rails/' }
end