Class: Yaml::Merge::NodeWrapper
- Inherits:
-
Ast::Merge::NodeWrapperBase
- Object
- Ast::Merge::NodeWrapperBase
- Yaml::Merge::NodeWrapper
- Defined in:
- lib/yaml/merge/node_wrapper.rb
Instance Attribute Summary collapse
-
#document_index ⇒ Object
readonly
Returns the value of attribute document_index.
Instance Method Summary collapse
- #body_node ⇒ Object
- #comment? ⇒ Boolean
- #container? ⇒ Boolean
- #document? ⇒ Boolean
- #header_lines_before(child) ⇒ Object
- #key_name ⇒ Object
- #mapping? ⇒ Boolean
- #mapping_pair? ⇒ Boolean
- #mapping_pairs ⇒ Object
- #mergeable_children ⇒ Object
- #process_additional_options(options) ⇒ Object
- #semantic_children ⇒ Object
- #sequence? ⇒ Boolean
- #unwrap_value_node ⇒ Object
- #value_node ⇒ Object
Instance Attribute Details
#document_index ⇒ Object (readonly)
Returns the value of attribute document_index.
6 7 8 |
# File 'lib/yaml/merge/node_wrapper.rb', line 6 def document_index @document_index end |
Instance Method Details
#body_node ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/yaml/merge/node_wrapper.rb', line 50 def body_node return unless document? semantic_children.find { |child| %w[block_node flow_node].include?(child.type.to_s) }&.then do |node| wrap_child(node).unwrap_value_node end end |
#comment? ⇒ Boolean
28 29 30 |
# File 'lib/yaml/merge/node_wrapper.rb', line 28 def comment? type?(:comment) end |
#container? ⇒ Boolean
32 33 34 |
# File 'lib/yaml/merge/node_wrapper.rb', line 32 def container? document? || mapping? end |
#document? ⇒ Boolean
12 13 14 |
# File 'lib/yaml/merge/node_wrapper.rb', line 12 def document? type?(:document) end |
#header_lines_before(child) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/yaml/merge/node_wrapper.rb', line 100 def header_lines_before(child) return [] unless start_line && child&.start_line first = start_line last = child.start_line - 1 return [] if last < first (first..last).filter_map { |line_num| @lines[line_num - 1] } end |
#key_name ⇒ Object
36 37 38 39 40 41 |
# File 'lib/yaml/merge/node_wrapper.rb', line 36 def key_name return unless mapping_pair? key = semantic_children.first scalar_text(key) end |
#mapping? ⇒ Boolean
16 17 18 |
# File 'lib/yaml/merge/node_wrapper.rb', line 16 def mapping? %i[block_mapping flow_mapping].include?(type) end |
#mapping_pair? ⇒ Boolean
24 25 26 |
# File 'lib/yaml/merge/node_wrapper.rb', line 24 def mapping_pair? type.to_s.end_with?('mapping_pair') end |
#mapping_pairs ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/yaml/merge/node_wrapper.rb', line 71 def mapping_pairs return [] unless mapping? semantic_children.filter_map do |child| wrapper = wrap_child(child) wrapper if wrapper.mapping_pair? end end |
#mergeable_children ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/yaml/merge/node_wrapper.rb', line 80 def mergeable_children if document? body = body_node body&.mapping? ? body.mapping_pairs : [] elsif mapping? mapping_pairs else [] end end |
#process_additional_options(options) ⇒ Object
8 9 10 |
# File 'lib/yaml/merge/node_wrapper.rb', line 8 def () @document_index = [:document_index] end |
#semantic_children ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/yaml/merge/node_wrapper.rb', line 91 def semantic_children return [] unless @node.respond_to?(:children) @node.children.select do |child| (!child.respond_to?(:named?) || child.named?) && child.type.to_s != 'comment' end end |
#sequence? ⇒ Boolean
20 21 22 |
# File 'lib/yaml/merge/node_wrapper.rb', line 20 def sequence? %i[block_sequence flow_sequence].include?(type) end |
#unwrap_value_node ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/yaml/merge/node_wrapper.rb', line 58 def unwrap_value_node current = self loop do break unless %i[block_node flow_node].include?(current.type) child = current.semantic_children.find { |candidate| !%w[anchor tag].include?(candidate.type.to_s) } break unless child current = current.wrap_child(child) end current end |
#value_node ⇒ Object
43 44 45 46 47 48 |
# File 'lib/yaml/merge/node_wrapper.rb', line 43 def value_node return unless mapping_pair? value = semantic_children[1] value ? wrap_child(value) : nil end |