Class: Pragmater::Writer
- Inherits:
-
Object
- Object
- Pragmater::Writer
- Defined in:
- lib/pragmater/writer.rb
Overview
Writes formatted pragma comments to source file. :reek:TooManyInstanceVariables :reek:PrimaDonnaMethod
Instance Method Summary collapse
-
#add ⇒ Object
rubocop:enable Metrics/ParameterLists.
-
#initialize(file_path, new_comments, formatter: Formatter, commenter: Commenter) ⇒ Writer
constructor
rubocop:disable Metrics/ParameterLists.
- #remove ⇒ Object
Constructor Details
#initialize(file_path, new_comments, formatter: Formatter, commenter: Commenter) ⇒ Writer
rubocop:disable Metrics/ParameterLists
9 10 11 12 13 14 15 16 |
# File 'lib/pragmater/writer.rb', line 9 def initialize file_path, new_comments, formatter: Formatter, commenter: Commenter @file_path = file_path @file_lines = File.readlines file_path @formatter = formatter @commenter = commenter @old_comments = file_comments @new_comments = new_comments end |
Instance Method Details
#add ⇒ Object
rubocop:enable Metrics/ParameterLists
19 20 21 22 23 24 |
# File 'lib/pragmater/writer.rb', line 19 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
26 27 28 29 30 |
# File 'lib/pragmater/writer.rb', line 26 def remove lines = format(commenter.new(old_comments, new_comments).remove) + file_lines_without_comments remove_spacing! lines write { lines.join } end |