Class: Psych::Merge::MappingEntry
- Inherits:
-
Object
- Object
- Psych::Merge::MappingEntry
- Defined in:
- lib/psych/merge/file_analysis.rb
Overview
Represents a key-value entry in a YAML mapping
Instance Attribute Summary collapse
-
#comment_tracker ⇒ CommentTracker
readonly
Comment tracker.
-
#key ⇒ NodeWrapper
readonly
The key node.
-
#lines ⇒ Array<String>
readonly
Source lines.
-
#value ⇒ NodeWrapper
readonly
The value node.
Instance Method Summary collapse
-
#anchor ⇒ String?
Get the anchor if present.
-
#comment_attachment ⇒ Ast::Merge::Comment::Attachment
Get a passive shared comment attachment for this mapping entry.
-
#content ⇒ String
Get the content for this entry.
-
#end_line ⇒ Integer?
Get the end line (from the value).
-
#freeze_node? ⇒ Boolean
Check if this is a freeze node.
-
#initialize(key:, value:, lines:, comment_tracker:) ⇒ MappingEntry
constructor
A new instance of MappingEntry.
-
#inline_comment_region ⇒ Ast::Merge::Comment::Region?
-
#inspect ⇒ String
String representation.
-
#key_name ⇒ String?
Get the key name as a string.
-
#leading_comment_region ⇒ Ast::Merge::Comment::Region?
-
#line_range ⇒ Range?
Get the line range.
-
#location ⇒ Object
Location-like object for compatibility.
-
#mapping? ⇒ Boolean
Check if this is a mapping.
-
#scalar? ⇒ Boolean
Check if this is a scalar.
-
#sequence? ⇒ Boolean
Check if this is a sequence.
-
#signature ⇒ Array
Generate signature for this entry.
-
#start_line ⇒ Integer?
Get the start line (from the key).
Constructor Details
#initialize(key:, value:, lines:, comment_tracker:) ⇒ MappingEntry
Returns a new instance of MappingEntry.
347 348 349 350 351 352 |
# File 'lib/psych/merge/file_analysis.rb', line 347 def initialize(key:, value:, lines:, comment_tracker:) @key = key @value = value @lines = lines @comment_tracker = comment_tracker end |
Instance Attribute Details
#comment_tracker ⇒ CommentTracker (readonly)
Returns Comment tracker.
341 342 343 |
# File 'lib/psych/merge/file_analysis.rb', line 341 def comment_tracker @comment_tracker end |
#key ⇒ NodeWrapper (readonly)
Returns The key node.
332 333 334 |
# File 'lib/psych/merge/file_analysis.rb', line 332 def key @key end |
#lines ⇒ Array<String> (readonly)
Returns Source lines.
338 339 340 |
# File 'lib/psych/merge/file_analysis.rb', line 338 def lines @lines end |
#value ⇒ NodeWrapper (readonly)
Returns The value node.
335 336 337 |
# File 'lib/psych/merge/file_analysis.rb', line 335 def value @value end |
Instance Method Details
#anchor ⇒ String?
Get the anchor if present
448 449 450 |
# File 'lib/psych/merge/file_analysis.rb', line 448 def anchor @value.anchor end |
#comment_attachment ⇒ Ast::Merge::Comment::Attachment
Get a passive shared comment attachment for this mapping entry.
357 358 359 360 361 362 363 364 365 |
# File 'lib/psych/merge/file_analysis.rb', line 357 def @comment_attachment ||= @comment_tracker.( self, line_num: @key.start_line, leading_comments: @comment_tracker.leading_comments_before(@key.start_line || 1), inline_comment: @comment_tracker.inline_comment_at(@key.start_line || 1), key_name: key_name, ) end |
#content ⇒ String
Get the content for this entry
405 406 407 408 409 |
# File 'lib/psych/merge/file_analysis.rb', line 405 def content return "" unless start_line && end_line (start_line..end_line).map { |ln| @lines[ln - 1] }.compact.join("\n") end |
#end_line ⇒ Integer?
Get the end line (from the value)
391 392 393 |
# File 'lib/psych/merge/file_analysis.rb', line 391 def end_line @value.end_line || @key.end_line end |
#freeze_node? ⇒ Boolean
Check if this is a freeze node
424 425 426 |
# File 'lib/psych/merge/file_analysis.rb', line 424 def freeze_node? false end |
#inline_comment_region ⇒ Ast::Merge::Comment::Region?
373 374 375 |
# File 'lib/psych/merge/file_analysis.rb', line 373 def inline_comment_region .inline_region end |
#inspect ⇒ String
String representation
454 455 456 |
# File 'lib/psych/merge/file_analysis.rb', line 454 def inspect "#<#{self.class.name} key=#{key_name.inspect} lines=#{start_line}..#{end_line}>" end |
#key_name ⇒ String?
Get the key name as a string
379 380 381 |
# File 'lib/psych/merge/file_analysis.rb', line 379 def key_name @key.value end |
#leading_comment_region ⇒ Ast::Merge::Comment::Region?
368 369 370 |
# File 'lib/psych/merge/file_analysis.rb', line 368 def leading_comment_region .leading_region end |
#line_range ⇒ Range?
Get the line range
397 398 399 400 401 |
# File 'lib/psych/merge/file_analysis.rb', line 397 def line_range return unless start_line && end_line start_line..end_line end |
#location ⇒ Object
Location-like object for compatibility
418 419 420 |
# File 'lib/psych/merge/file_analysis.rb', line 418 def location @location ||= FreezeNode::Location.new(start_line, end_line) end |
#mapping? ⇒ Boolean
Check if this is a mapping
430 431 432 |
# File 'lib/psych/merge/file_analysis.rb', line 430 def mapping? @value.mapping? end |
#scalar? ⇒ Boolean
Check if this is a scalar
442 443 444 |
# File 'lib/psych/merge/file_analysis.rb', line 442 def scalar? @value.scalar? end |
#sequence? ⇒ Boolean
Check if this is a sequence
436 437 438 |
# File 'lib/psych/merge/file_analysis.rb', line 436 def sequence? @value.sequence? end |
#signature ⇒ Array
Generate signature for this entry
413 414 415 |
# File 'lib/psych/merge/file_analysis.rb', line 413 def signature [:mapping_entry, key_name] end |
#start_line ⇒ Integer?
Get the start line (from the key)
385 386 387 |
# File 'lib/psych/merge/file_analysis.rb', line 385 def start_line leading_comment_region&.start_line || @key.start_line end |