Class: SchemaGraphy::CFGYML::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/schemagraphy/cfgyml/definition.rb

Overview

Represents a configuration definition loaded from a schema file. It provides methods for accessing defaults and rendering documentation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema_path, attrs = {}) ⇒ Definition

Returns a new instance of Definition.

Parameters:

  • schema_path (String)
    The path to the schema YAML file.
  • attrs (Hash) (defaults to: {})
    A hash of attributes for placeholder resolution.


20
21
22
23
# File 'lib/schemagraphy/cfgyml/definition.rb', line 20

def initialize schema_path, attrs = {}
  @schema = Loader.load_yaml_with_attributes(schema_path, attrs)
  @attributes = attrs
end

Instance Attribute Details

#attributesHash (readonly)

Returns The attributes used for resolving placeholders in the schema.

Returns:

  • (Hash)
    The attributes used for resolving placeholders in the schema.


16
17
18
# File 'lib/schemagraphy/cfgyml/definition.rb', line 16

def attributes
  @attributes
end

#schemaHash (readonly)

Returns The loaded schema hash.

Returns:

  • (Hash)
    The loaded schema hash.


13
14
15
# File 'lib/schemagraphy/cfgyml/definition.rb', line 13

def schema
  @schema
end

Instance Method Details

#defaultsHash

Extract default values from the loaded schema.

Returns:

  • (Hash)
    A hash of default values.


27
28
29
# File 'lib/schemagraphy/cfgyml/definition.rb', line 27

def defaults
  SchemaUtils.crawl_defaults(@schema)
end

#render_reference(format = :adoc) ⇒ String

Render a configuration reference or sample in the specified format.

Parameters:

  • format (Symbol) (defaults to: :adoc)
    The output format (`:adoc` or `:yaml`).

Returns:

  • (String)
    The rendered output.

Raises:

  • (ArgumentError)
    if the format is unsupported.


45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/schemagraphy/cfgyml/definition.rb', line 45

def render_reference format = :adoc
  template = case format
             when :adoc
               'config-reference.adoc.liquid'
             when :yaml
               'sample-config.yaml.liquid'
             else
               raise ArgumentError, "Unsupported format: #{format}"
             end

  render_template(template)
end

#template_pathsArray<String>

Get the search paths for templates.

Returns:

  • (Array<String>)
    An array of template paths.


33
34
35
36
37
38
# File 'lib/schemagraphy/cfgyml/definition.rb', line 33

def template_paths
  @template_paths ||= [
    File.join(File.dirname(__FILE__), '..', 'templates', 'cfgyml'),
    *additional_template_paths
  ]
end