Module: Psych::Merge::NativeProjection
- Defined in:
- lib/psych/merge/native_projection.rb
Overview
Shared native Psych projection used by semantic verification and contract snapshot extensions. Location and ownership remain separate concerns.
Constant Summary collapse
- ATTRIBUTE_NAMES =
%i[anchor tag style plain quoted implicit implicit_end version tag_directives].freeze
Class Method Summary collapse
- .attribute_tree(node) ⇒ Object
- .attributes(node) ⇒ Object
- .public_value(value) ⇒ Object
- .semantic(node) ⇒ Object
Class Method Details
.attribute_tree(node) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/psych/merge/native_projection.rb', line 21 def attribute_tree(node) { attributes: attributes(node), children: children(node).map { |child| attribute_tree(child) } }.freeze end |
.attributes(node) ⇒ Object
28 29 30 31 32 |
# File 'lib/psych/merge/native_projection.rb', line 28 def attributes(node) ATTRIBUTE_NAMES.each_with_object({}) do |name, result| result[name] = public_value(node.public_send(name)) if node.respond_to?(name) end.freeze end |
.public_value(value) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/psych/merge/native_projection.rb', line 34 def public_value(value) case value when Array then value.map { |item| public_value(item) } when Hash then value.to_h { |key, item| [key.to_s, public_value(item)] } when String, Integer, Float, TrueClass, FalseClass, NilClass then value else value.to_s end end |
.semantic(node) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/psych/merge/native_projection.rb', line 12 def semantic(node) { type: node.class.name.delete_prefix('Psych::Nodes::'), value: (node.value if node.respond_to?(:value)), tag: (node.tag if node.respond_to?(:tag)), children: children(node).map { |child| semantic(child) } }.compact.freeze end |