Skip to content

Commit a84af5e

Browse files
Wrap annotations
1 parent e5bedc0 commit a84af5e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/annotate/annotate_models.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,18 @@ def annotate_one_file(file_name, info_block, position, options={})
253253
new_content = old_content.sub(PATTERN, "\n" + info_block)
254254
end
255255

256+
wrapper_open = options[:wrapper_open] ? "# #{options[:wrapper_open]}\n" : ""
257+
wrapper_close = options[:wrapper_close] ? "\n# #{options[:wrapper_close]}" : ""
258+
wrapped_info_block = "#{wrapper_open}#{info_block}#{wrapper_close}"
256259
# if there *was* no old schema info (no substitution happened) or :force was passed,
257260
# we simply need to insert it in correct position
258261
if new_content == old_content || options[:force]
259262
old_content.sub!(encoding, '')
260263
old_content.sub!(PATTERN, '')
261264

262265
new_content = %w(after bottom).include?(options[position].to_s) ?
263-
(encoding_header + (old_content.rstrip + "\n\n" + info_block)) :
264-
(encoding_header + info_block + "\n" + old_content)
266+
(encoding_header + (old_content.rstrip + "\n\n" + wrapped_info_block)) :
267+
(encoding_header + wrapped_info_block + "\n" + old_content)
265268
end
266269

267270
File.open(file_name, "wb") { |f| f.puts new_content }

spec/annotate/annotate_models_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ def encoding_comments_list_each
456456
end
457457

458458
it 'should wrap annotation if wrapper is specified' do
459-
annotate_one_file :wrapper_beg => 'START', :wrapper_end => 'END'
460-
expect(File.read(@model_file_name)).to eq("START\n#{@schema_info}\nEND\n#{@file_content}")
459+
annotate_one_file :wrapper_open => 'START', :wrapper_close => 'END'
460+
expect(File.read(@model_file_name)).to eq("# START\n#{@schema_info}\n# END\n#{@file_content}")
461461
end
462462

463463
describe "with existing annotation => :before" do

0 commit comments

Comments
 (0)