Class: SchemaGraphy::Loader
- Inherits:
-
Object
- Object
- SchemaGraphy::Loader
- Defined in:
- lib/schemagraphy/loader.rb
Overview
The Loader class provides methods for loading YAML files while preserving
custom tags and resolving attribute references.
Class Method Summary collapse
-
.attach_tags(node, data) ⇒ Object
private
Recursively attach YAML tags to the loaded data structure for template processing.
-
.load_yaml_with_attributes(path, attrs = {}) ⇒ Hash
Load a YAML file and resolve AsciiDoc attribute references like `{attribute_name}`.
-
.load_yaml_with_tags(path) ⇒ Hash
Load a YAML file, preserving any custom tags (e.g., `!foo`).
Class Method Details
.attach_tags(node, data) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Recursively attach YAML tags to the loaded data structure for template processing.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/schemagraphy/loader.rb', line 41 def self. node, data return unless node.is_a?(Psych::Nodes::Mapping) node.children.each_slice(2) do |key_node, val_node| key = key_node.value if val_node.respond_to?(:tag) && val_node.tag && data[key].is_a?(String) normalized_tag = val_node.tag.sub(/^!+/, '').sub(/^.*:/, '') data[key] = { 'value' => data[key], '__tag__' => normalized_tag } elsif data[key].is_a?(Hash) (val_node, data[key]) end end end |
.load_yaml_with_attributes(path, attrs = {}) ⇒ Hash
Load a YAML file and resolve AsciiDoc attribute references like `{attribute_name}`.
16 17 18 19 20 |
# File 'lib/schemagraphy/loader.rb', line 16 def self.load_yaml_with_attributes path, attrs = {} raw_data = (path) AttributeResolver.resolve_attributes!(raw_data, attrs) raw_data end |
.load_yaml_with_tags(path) ⇒ Hash
Load a YAML file, preserving any custom tags (e.g., `!foo`).
Custom tags are attached to the data structure.
27 28 29 30 31 32 33 34 |
# File 'lib/schemagraphy/loader.rb', line 27 def self. path return {} if File.empty?(path) data = Psych.load_file(path, aliases: true, permitted_classes: [Date, Time]) ast = Psych.parse_file(path) (ast.root, data) data end |