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.
452 453 454 455 456 457 |
# File 'lib/psych/merge/file_analysis.rb', line 452 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.
446 447 448 |
# File 'lib/psych/merge/file_analysis.rb', line 446 def comment_tracker @comment_tracker end |
#key ⇒ NodeWrapper (readonly)
Returns The key node.
437 438 439 |
# File 'lib/psych/merge/file_analysis.rb', line 437 def key @key end |
#lines ⇒ Array<String> (readonly)
Returns Source lines.
443 444 445 |
# File 'lib/psych/merge/file_analysis.rb', line 443 def lines @lines end |
#value ⇒ NodeWrapper (readonly)
Returns The value node.
440 441 442 |
# File 'lib/psych/merge/file_analysis.rb', line 440 def value @value end |
Instance Method Details
#anchor ⇒ String?
Get the anchor if present
553 554 555 |
# File 'lib/psych/merge/file_analysis.rb', line 553 def anchor @value.anchor end |
#comment_attachment ⇒ Ast::Merge::Comment::Attachment
Get a passive shared comment attachment for this mapping entry.
462 463 464 465 466 467 468 469 470 |
# File 'lib/psych/merge/file_analysis.rb', line 462 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
510 511 512 513 514 |
# File 'lib/psych/merge/file_analysis.rb', line 510 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)
496 497 498 |
# File 'lib/psych/merge/file_analysis.rb', line 496 def end_line @value.end_line || @key.end_line end |
#freeze_node? ⇒ Boolean
Check if this is a freeze node
529 530 531 |
# File 'lib/psych/merge/file_analysis.rb', line 529 def freeze_node? false end |
#inline_comment_region ⇒ Ast::Merge::Comment::Region?
478 479 480 |
# File 'lib/psych/merge/file_analysis.rb', line 478 def inline_comment_region .inline_region end |
#inspect ⇒ String
String representation
559 560 561 |
# File 'lib/psych/merge/file_analysis.rb', line 559 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
484 485 486 |
# File 'lib/psych/merge/file_analysis.rb', line 484 def key_name @key.value end |
#leading_comment_region ⇒ Ast::Merge::Comment::Region?
473 474 475 |
# File 'lib/psych/merge/file_analysis.rb', line 473 def leading_comment_region .leading_region end |
#line_range ⇒ Range?
Get the line range
502 503 504 505 506 |
# File 'lib/psych/merge/file_analysis.rb', line 502 def line_range return unless start_line && end_line start_line..end_line end |
#location ⇒ Object
Location-like object for compatibility
523 524 525 |
# File 'lib/psych/merge/file_analysis.rb', line 523 def location @location ||= FreezeNode::Location.new(start_line, end_line) end |
#mapping? ⇒ Boolean
Check if this is a mapping
535 536 537 |
# File 'lib/psych/merge/file_analysis.rb', line 535 def mapping? @value.mapping? end |
#scalar? ⇒ Boolean
Check if this is a scalar
547 548 549 |
# File 'lib/psych/merge/file_analysis.rb', line 547 def scalar? @value.scalar? end |
#sequence? ⇒ Boolean
Check if this is a sequence
541 542 543 |
# File 'lib/psych/merge/file_analysis.rb', line 541 def sequence? @value.sequence? end |
#signature ⇒ Array
Generate signature for this entry
518 519 520 |
# File 'lib/psych/merge/file_analysis.rb', line 518 def signature [:mapping_entry, key_name] end |
#start_line ⇒ Integer?
Get the start line (from the key)
490 491 492 |
# File 'lib/psych/merge/file_analysis.rb', line 490 def start_line leading_comment_region&.start_line || @key.start_line end |