Class: AnnotateRb::ModelAnnotator::FileBuilder
- Inherits:
-
Object
- Object
- AnnotateRb::ModelAnnotator::FileBuilder
- Defined in:
- lib/annotate_rb/model_annotator/file_builder.rb
Overview
Generates the text file content with annotations, these are then to be written to filesystem.
Instance Method Summary collapse
- #generate_content_with_new_annotations ⇒ Object
-
#initialize(file_components, new_annotations, annotation_position, options) ⇒ FileBuilder
constructor
A new instance of FileBuilder.
- #update_existing_annotations ⇒ Object
Constructor Details
#initialize(file_components, new_annotations, annotation_position, options) ⇒ FileBuilder
Returns a new instance of FileBuilder.
7 8 9 10 11 12 13 14 |
# File 'lib/annotate_rb/model_annotator/file_builder.rb', line 7 def initialize(file_components, new_annotations, annotation_position, ) @file_components = file_components @new_annotations = new_annotations @annotation_position = annotation_position = @new_wrapped_annotations = wrapped_content(new_annotations) end |
Instance Method Details
#generate_content_with_new_annotations ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/annotate_rb/model_annotator/file_builder.rb', line 16 def generate_content_with_new_annotations # Need to keep `.to_s` for now since the it can be either a String or Symbol annotation_write_position = [@annotation_position].to_s _content = if %w[after bottom].include?(annotation_write_position) @file_components.magic_comments + (@file_components.pure_file_content.rstrip + "\n\n" + @new_wrapped_annotations) elsif @file_components.magic_comments.empty? @file_components.magic_comments + @new_wrapped_annotations + @file_components.pure_file_content.lstrip else @file_components.magic_comments + "\n" + @new_wrapped_annotations + @file_components.pure_file_content.lstrip end end |
#update_existing_annotations ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/annotate_rb/model_annotator/file_builder.rb', line 29 def update_existing_annotations return "" if !@file_components.has_annotations? annotation_pattern = AnnotationPatternGenerator.call() new_annotation = @file_components.space_before_annotation + @new_wrapped_annotations + @file_components.space_after_annotation _content = @file_components.current_file_content.sub(annotation_pattern, new_annotation) end |