Commit a84af5e8 by Kamil Bielawski

Wrap annotations

parent e5bedc0d
......@@ -253,6 +253,9 @@ module AnnotateModels
new_content = old_content.sub(PATTERN, "\n" + info_block)
end
wrapper_open = options[:wrapper_open] ? "# #{options[:wrapper_open]}\n" : ""
wrapper_close = options[:wrapper_close] ? "\n# #{options[:wrapper_close]}" : ""
wrapped_info_block = "#{wrapper_open}#{info_block}#{wrapper_close}"
# if there *was* no old schema info (no substitution happened) or :force was passed,
# we simply need to insert it in correct position
if new_content == old_content || options[:force]
......@@ -260,8 +263,8 @@ module AnnotateModels
old_content.sub!(PATTERN, '')
new_content = %w(after bottom).include?(options[position].to_s) ?
(encoding_header + (old_content.rstrip + "\n\n" + info_block)) :
(encoding_header + info_block + "\n" + old_content)
(encoding_header + (old_content.rstrip + "\n\n" + wrapped_info_block)) :
(encoding_header + wrapped_info_block + "\n" + old_content)
end
File.open(file_name, "wb") { |f| f.puts new_content }
......
......@@ -456,8 +456,8 @@ end
end
it 'should wrap annotation if wrapper is specified' do
annotate_one_file :wrapper_beg => 'START', :wrapper_end => 'END'
expect(File.read(@model_file_name)).to eq("START\n#{@schema_info}\nEND\n#{@file_content}")
annotate_one_file :wrapper_open => 'START', :wrapper_close => 'END'
expect(File.read(@model_file_name)).to eq("# START\n#{@schema_info}\n# END\n#{@file_content}")
end
describe "with existing annotation => :before" do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment