Skip to content

Commit 57b92fe

Browse files
committed
decide when run rake or rails routes.
1 parent 3a78787 commit 57b92fe

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ when using `SpatialAdapter`, `PostgisAdapter` or `PostGISAdapter`:
4949
# path :geometry line_string, 4326
5050
```
5151

52-
Also, if you pass the `-r` option, it'll annotate `routes.rb` with the output of `rake routes`.
52+
Also, if you pass the `-r` option, it'll annotate `routes.rb` with the output of `rake/rails routes`.
5353

5454

5555
## 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
217217
If --w option is used, the same text will be used as opening and closing
218218
--wo, --wrapper-open STR Annotation wrapper opening.
219219
--wc, --wrapper-close STR Annotation wrapper closing
220-
-r, --routes Annotate routes.rb with the output of 'rake routes'
220+
-r, --routes Annotate routes.rb with the output of 'rake/rails routes'
221221
--models Annotate ActiveRecord models
222222
-a, --active-admin Annotate active_admin models
223223
-v, --version Show the current version of this gem

lib/annotate/annotate_routes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
#
66
#
7-
# Prepends the output of "rake routes" to the top of your routes.rb file.
7+
# Prepends the output of "rake/rails routes" to the top of your routes.rb file.
88
# Yes, it's simple but I'm thick and often need a reminder of what my routes
99
# mean.
1010
#

lib/annotate/annotate_routes/header_generator.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def generate(options = {})
1616
private
1717

1818
def routes_map(options)
19-
result = `rake routes`.chomp("\n").split(/\n/, -1)
19+
command = Rails.version.first.to_i > 5 ? `rails routes` : `rake routes`
20+
result = command.chomp("\n").split(/\n/, -1)
2021

2122
# In old versions of Rake, the first line of output was the cwd. Not so
2223
# much in newer ones. We ditch that line if it exists, and if not, we

lib/annotate/parser.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength,
145145

146146
option_parser.on('-r',
147147
'--routes',
148-
"Annotate routes.rb with the output of 'rake routes'") do
148+
"Annotate routes.rb with the output of 'rake/rails routes'") do
149149
env['routes'] = 'true'
150150
end
151151

0 commit comments

Comments
 (0)