Class: Canon::TreeDiff::Adapters::YAMLAdapter
- Inherits:
-
Object
- Object
- Canon::TreeDiff::Adapters::YAMLAdapter
- Defined in:
- lib/canon/tree_diff/adapters/yaml_adapter.rb
Overview
YAMLAdapter converts YAML structures to TreeNode structures and back, enabling semantic tree diffing on YAML documents.
This adapter:
-
Converts Hash/Array YAML structures to TreeNode tree
-
Handles nested objects, arrays, and primitive values
-
Preserves type information for round-trip conversion
-
Maps YAML structure to tree representation
YAML to TreeNode mapping (similar to JSON):
-
Objects (Hash): TreeNode with label “object”, children for each key
-
Arrays: TreeNode with label “array”, indexed children
-
Primitives: TreeNode with label “value”, value stored directly
Instance Attribute Summary collapse
-
#match_options ⇒ Object
readonly
Returns the value of attribute match_options.
Instance Method Summary collapse
-
#from_tree(tree_node) ⇒ Hash, ...
Convert TreeNode back to YAML structure.
-
#initialize(match_options: {}) ⇒ YAMLAdapter
constructor
Initialize adapter with match options.
-
#to_tree(data, key = nil) ⇒ Core::TreeNode
Convert YAML structure to TreeNode.
Constructor Details
#initialize(match_options: {}) ⇒ YAMLAdapter
Initialize adapter with match options
33 34 35 |
# File 'lib/canon/tree_diff/adapters/yaml_adapter.rb', line 33 def initialize(match_options: {}) @match_options = end |
Instance Attribute Details
#match_options ⇒ Object (readonly)
Returns the value of attribute match_options.
28 29 30 |
# File 'lib/canon/tree_diff/adapters/yaml_adapter.rb', line 28 def @match_options end |
Instance Method Details
#from_tree(tree_node) ⇒ Hash, ...
Convert TreeNode back to YAML structure
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/canon/tree_diff/adapters/yaml_adapter.rb', line 57 def from_tree(tree_node) case tree_node.label when "object" build_object(tree_node) when "array" build_array(tree_node) when "value" parse_value(tree_node) else # Fallback for custom labels tree_node.value end end |
#to_tree(data, key = nil) ⇒ Core::TreeNode
Convert YAML structure to TreeNode
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/canon/tree_diff/adapters/yaml_adapter.rb', line 42 def to_tree(data, key = nil) case data when Hash convert_object(data, key) when Array convert_array(data, key) else convert_value(data, key) end end |