diff --git a/README.md b/README.md index abf325ffa..85a899211 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ when using `SpatialAdapter`, `PostgisAdapter` or `PostGISAdapter`: # path :geometry line_string, 4326 ``` -Also, if you pass the `-r` option, it'll annotate `routes.rb` with the output of `rake routes`. +Also, if you pass the `-r` option, it'll annotate `routes.rb` with the output of `rake/rails routes`. ## Upgrading to 3.X and annotate models not working? @@ -217,7 +217,7 @@ you can do so with a simple environment variable, instead of editing the If --w option is used, the same text will be used as opening and closing --wo, --wrapper-open STR Annotation wrapper opening. --wc, --wrapper-close STR Annotation wrapper closing - -r, --routes Annotate routes.rb with the output of 'rake routes' + -r, --routes Annotate routes.rb with the output of 'rake/rails routes' --models Annotate ActiveRecord models -a, --active-admin Annotate active_admin models -v, --version Show the current version of this gem diff --git a/lib/annotate/annotate_routes.rb b/lib/annotate/annotate_routes.rb index c9a2218ac..56c6a342c 100644 --- a/lib/annotate/annotate_routes.rb +++ b/lib/annotate/annotate_routes.rb @@ -4,7 +4,7 @@ # # # -# Prepends the output of "rake routes" to the top of your routes.rb file. +# Prepends the output of "rake/rails routes" to the top of your routes.rb file. # Yes, it's simple but I'm thick and often need a reminder of what my routes # mean. # diff --git a/lib/annotate/annotate_routes/header_generator.rb b/lib/annotate/annotate_routes/header_generator.rb index b1c93acf7..94665151f 100644 --- a/lib/annotate/annotate_routes/header_generator.rb +++ b/lib/annotate/annotate_routes/header_generator.rb @@ -1,3 +1,4 @@ +require 'active_record' require_relative './helpers' module AnnotateRoutes @@ -16,7 +17,8 @@ def generate(options = {}) private def routes_map(options) - result = `rake routes`.chomp("\n").split(/\n/, -1) + command = ActiveRecord.version.to_s.first.to_i > 5 ? `rails routes` : `rake routes` + result = command.chomp("\n").split(/\n/, -1) # In old versions of Rake, the first line of output was the cwd. Not so # much in newer ones. We ditch that line if it exists, and if not, we diff --git a/lib/annotate/parser.rb b/lib/annotate/parser.rb index 3f5ebdb00..5feaad3ca 100644 --- a/lib/annotate/parser.rb +++ b/lib/annotate/parser.rb @@ -145,7 +145,7 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength, option_parser.on('-r', '--routes', - "Annotate routes.rb with the output of 'rake routes'") do + "Annotate routes.rb with the output of 'rake/rails routes'") do env['routes'] = 'true' end