Class: Pragmater::Writer
- Inherits:
-
Object
- Object
- Pragmater::Writer
- Defined in:
- lib/pragmater/writer.rb
Overview
Writes formatted pragma comments to source file.
Instance Method Summary collapse
- #add ⇒ Object
-
#initialize(file_path, new_comments, formatter: Formatter, commenter: Commenter) ⇒ Writer
constructor
A new instance of Writer.
- #remove ⇒ Object
Constructor Details
#initialize(file_path, new_comments, formatter: Formatter, commenter: Commenter) ⇒ Writer
Returns a new instance of Writer.
6 7 8 9 10 11 12 13 |
# File 'lib/pragmater/writer.rb', line 6 def initialize file_path, new_comments, formatter: Formatter, commenter: Commenter @file_path = file_path @file_lines = File.open(file_path).to_a @formatter = formatter @commenter = commenter @old_comments = file_comments @new_comments = new_comments end |
Instance Method Details
#add ⇒ Object
15 16 17 18 19 20 |
# File 'lib/pragmater/writer.rb', line 15 def add comments = format commenter.new(old_comments, new_comments).add lines = comments + file_lines_without_comments insert_spacing! lines, comments write { lines.join } end |
#remove ⇒ Object
22 23 24 25 26 |
# File 'lib/pragmater/writer.rb', line 22 def remove lines = format(commenter.new(old_comments, new_comments).remove) + file_lines_without_comments remove_spacing! lines write { lines.join } end |