Class: Udb::Yaml::CommentMap
- Inherits:
-
Object
- Object
- Udb::Yaml::CommentMap
- Extended by:
- T::Sig
- Defined in:
- lib/udb/yaml/comment_parser.rb
Overview
Maps key paths to their associated comments and string styles
Instance Attribute Summary collapse
-
#header_comments ⇒ Object
readonly
Returns the value of attribute header_comments.
-
#trailing_comments ⇒ Object
readonly
Returns the value of attribute trailing_comments.
Instance Method Summary collapse
- #add_comment(key_path, comment) ⇒ Object
- #add_header_comment(comment) ⇒ Object
- #add_trailing_comment(comment) ⇒ Object
- #all_comments ⇒ Object
- #all_source_locations ⇒ Object
- #get_comments(key_path) ⇒ Object
- #get_multiline_content(key_path) ⇒ Object
- #get_source_location(key_path) ⇒ Object
- #get_string_style(key_path) ⇒ Object
-
#initialize ⇒ CommentMap
constructor
A new instance of CommentMap.
- #merge_styles_from(base_map) ⇒ Object
- #set_multiline_content(key_path, lines) ⇒ Object
- #set_source_location(key_path, file, line, column, offset = nil, line_file_offsets = nil) ⇒ Object
- #set_string_style(key_path, style) ⇒ Object
Constructor Details
#initialize ⇒ CommentMap
Returns a new instance of CommentMap.
59 60 61 62 63 64 65 66 |
# File 'lib/udb/yaml/comment_parser.rb', line 59 def initialize @comments = T.let({}, T::Hash[String, T::Array[Comment]]) @header_comments = T.let([], T::Array[Comment]) @trailing_comments = T.let([], T::Array[Comment]) @string_styles = T.let({}, T::Hash[String, Symbol]) @multiline_content = T.let({}, T::Hash[String, T::Array[String]]) @source_locations = T.let({}, T::Hash[String, T::Hash[Symbol, T.untyped]]) end |
Instance Attribute Details
#header_comments ⇒ Object (readonly)
Returns the value of attribute header_comments.
69 70 71 |
# File 'lib/udb/yaml/comment_parser.rb', line 69 def header_comments @header_comments end |
#trailing_comments ⇒ Object (readonly)
Returns the value of attribute trailing_comments.
72 73 74 |
# File 'lib/udb/yaml/comment_parser.rb', line 72 def trailing_comments @trailing_comments end |
Instance Method Details
#add_comment(key_path, comment) ⇒ Object
89 90 91 92 93 |
# File 'lib/udb/yaml/comment_parser.rb', line 89 def add_comment(key_path, comment) path_key = path_key_for(key_path) @comments[path_key] ||= [] @comments.fetch(path_key) << comment end |
#add_header_comment(comment) ⇒ Object
104 105 106 |
# File 'lib/udb/yaml/comment_parser.rb', line 104 def add_header_comment(comment) @header_comments << comment end |
#add_trailing_comment(comment) ⇒ Object
109 110 111 |
# File 'lib/udb/yaml/comment_parser.rb', line 109 def add_trailing_comment(comment) @trailing_comments << comment end |
#all_comments ⇒ Object
190 191 192 |
# File 'lib/udb/yaml/comment_parser.rb', line 190 def all_comments @comments.values.flatten + @header_comments + @trailing_comments end |
#all_source_locations ⇒ Object
185 186 187 |
# File 'lib/udb/yaml/comment_parser.rb', line 185 def all_source_locations @source_locations end |
#get_comments(key_path) ⇒ Object
98 99 100 101 |
# File 'lib/udb/yaml/comment_parser.rb', line 98 def get_comments(key_path) path_key = path_key_for(key_path) @comments[path_key] || [] end |
#get_multiline_content(key_path) ⇒ Object
156 157 158 159 |
# File 'lib/udb/yaml/comment_parser.rb', line 156 def get_multiline_content(key_path) path_key = path_key_for(key_path) @multiline_content[path_key] end |
#get_source_location(key_path) ⇒ Object
179 180 181 182 |
# File 'lib/udb/yaml/comment_parser.rb', line 179 def get_source_location(key_path) path_key = path_key_for(key_path) @source_locations[path_key] end |
#get_string_style(key_path) ⇒ Object
127 128 129 130 |
# File 'lib/udb/yaml/comment_parser.rb', line 127 def get_string_style(key_path) path_key = path_key_for(key_path) @string_styles[path_key] end |
#merge_styles_from(base_map) ⇒ Object
136 137 138 139 140 |
# File 'lib/udb/yaml/comment_parser.rb', line 136 def merge_styles_from(base_map) base_map.instance_variable_get(:@string_styles).each do |path_key, style| @string_styles[path_key] ||= style end end |
#set_multiline_content(key_path, lines) ⇒ Object
148 149 150 151 |
# File 'lib/udb/yaml/comment_parser.rb', line 148 def set_multiline_content(key_path, lines) path_key = path_key_for(key_path) @multiline_content[path_key] = lines end |
#set_source_location(key_path, file, line, column, offset = nil, line_file_offsets = nil) ⇒ Object
171 172 173 174 |
# File 'lib/udb/yaml/comment_parser.rb', line 171 def set_source_location(key_path, file, line, column, offset = nil, line_file_offsets = nil) path_key = path_key_for(key_path) @source_locations[path_key] = { file: file.to_s, line: line, column: column, offset: offset, line_file_offsets: line_file_offsets } end |
#set_string_style(key_path, style) ⇒ Object
119 120 121 122 |
# File 'lib/udb/yaml/comment_parser.rb', line 119 def set_string_style(key_path, style) path_key = path_key_for(key_path) @string_styles[path_key] = style end |