Class: SchemaGraphy::CFGYML::Definition
- Inherits:
-
Object
- Object
- SchemaGraphy::CFGYML::Definition
- 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
-
#attributes ⇒ Hash
readonly
The attributes used for resolving placeholders in the schema.
-
#schema ⇒ Hash
readonly
The loaded schema hash.
Instance Method Summary collapse
-
#defaults ⇒ Hash
Extract default values from the loaded schema.
-
#initialize(schema_path, attrs = {}) ⇒ Definition
constructor
A new instance of Definition.
-
#render_reference(format = :adoc) ⇒ String
Render a configuration reference or sample in the specified format.
-
#template_paths ⇒ Array<String>
Get the search paths for templates.
Constructor Details
#initialize(schema_path, attrs = {}) ⇒ Definition
Returns a new instance of Definition.
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
#attributes ⇒ Hash (readonly)
Returns The attributes used for resolving placeholders in the schema.
16 17 18 |
# File 'lib/schemagraphy/cfgyml/definition.rb', line 16 def attributes @attributes end |
#schema ⇒ Hash (readonly)
Returns The loaded schema hash.
13 14 15 |
# File 'lib/schemagraphy/cfgyml/definition.rb', line 13 def schema @schema end |
Instance Method Details
#defaults ⇒ Hash
Extract default values from the loaded schema.
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.
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_paths ⇒ Array<String>
Get the search paths for templates.
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 |