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

Note:

This method is a placeholder. SchemaUtils.crawl_defaults/1 is not yet implemented.

Extract default values from the loaded schema.

Returns:

  • (Hash)

    A hash of default values.



28
29
30
31
32
# File 'lib/schemagraphy/cfgyml/definition.rb', line 28

def defaults
  # TODO: Implement crawl_defaults in SchemaUtils
  # For now, return an empty hash
  {}
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.



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/schemagraphy/cfgyml/definition.rb', line 48

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.



36
37
38
39
40
41
# File 'lib/schemagraphy/cfgyml/definition.rb', line 36

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