Skip to content

Commit e763429

Browse files
sashabelozerovctran
authored andcommitted
[Fix #401] Allow wrappers in routes annotation (#492)
1 parent 240c6b2 commit e763429

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

lib/annotate/annotate_routes.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# rubocop:disable Metrics/ModuleLength
2+
13
# == Annotate Routes
24
#
35
# Based on:
@@ -36,7 +38,10 @@ def content(line, maxs, options = {})
3638
def header(options = {})
3739
routes_map = app_routes_map(options)
3840

39-
out = ["# #{options[:format_markdown] ? PREFIX_MD : PREFIX}" + (options[:timestamp] ? " (Updated #{Time.now.strftime('%Y-%m-%d %H:%M')})" : '')]
41+
out = []
42+
out += ["# #{options[:wrapper_open]}"] if options[:wrapper_open]
43+
44+
out += ["# #{options[:format_markdown] ? PREFIX_MD : PREFIX}" + (options[:timestamp] ? " (Updated #{Time.now.strftime('%Y-%m-%d %H:%M')})" : '')]
4045
out += ['#']
4146
return out if routes_map.size.zero?
4247

@@ -51,7 +56,10 @@ def header(options = {})
5156
out += ["# #{content(routes_map[0], maxs, options)}"]
5257
end
5358

54-
out + routes_map[1..-1].map { |line| "# #{content(options[:format_markdown] ? line.split(' ') : line, maxs, options)}" }
59+
out += routes_map[1..-1].map { |line| "# #{content(options[:format_markdown] ? line.split(' ') : line, maxs, options)}" }
60+
out += ["# #{options[:wrapper_close]}"] if options[:wrapper_close]
61+
62+
out
5563
end
5664

5765
def do_annotations(options = {})

lib/tasks/annotate_routes.rake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ task :annotate_routes => :environment do
88
options[:position_in_routes] = Annotate.fallback(ENV['position_in_routes'], ENV['position'])
99
options[:ignore_routes] = Annotate.fallback(ENV['ignore_routes'], nil)
1010
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
11+
options[:wrapper_open] = Annotate.fallback(ENV['wrapper_open'], ENV['wrapper'])
12+
options[:wrapper_close] = Annotate.fallback(ENV['wrapper_close'], ENV['wrapper'])
1113
AnnotateRoutes.do_annotations(options)
1214
end
1315

spec/annotate/annotate_routes_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ def mock_file(stubs = {})
5656

5757
AnnotateRoutes.do_annotations(format_markdown: true)
5858
end
59+
60+
it 'wraps annotation if wrapper is specified' do
61+
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
62+
expect(@mock_file).to receive(:puts).with("
63+
# START
64+
# == Route Map
65+
#
66+
# Prefix Verb URI Pattern Controller#Action
67+
# myaction1 GET /url1(.:format) mycontroller1#action
68+
# myaction2 POST /url2(.:format) mycontroller2#action
69+
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
70+
# END\n")
71+
72+
AnnotateRoutes.do_annotations(wrapper_open: 'START', wrapper_close: 'END')
73+
end
5974
end
6075

6176
describe 'When adding' do

0 commit comments

Comments
 (0)