Module: SchemaGraphy::CFGYML::DocBuilder
- Defined in:
- lib/schemagraphy/cfgyml/doc_builder.rb
Overview
Builds documentation-friendly CFGYML references for machine consumption.
Class Method Summary
collapse
Class Method Details
.build_entry(path, definition) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/schemagraphy/cfgyml/doc_builder.rb', line 39
def build_entry path, definition
entry = {
'path' => path.join('.'),
'desc' => definition['desc'],
'docs' => definition['docs'],
'type' => definition['type'],
'templating' => definition['templating'],
'default' => definition.key?('dflt') ? definition['dflt'] : nil
}
entry.compact
end
|
.build_properties(properties, path) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/schemagraphy/cfgyml/doc_builder.rb', line 25
def build_properties properties, path
return {} unless properties.is_a?(Hash)
properties.each_with_object({}) do |(key, definition), acc|
next unless definition.is_a?(Hash)
current_path = path + [key]
entry = build_entry(current_path, definition)
children = build_properties(definition['properties'], current_path)
entry['properties'] = children unless children.empty?
acc[key] = entry
end
end
|
.call(schema, options = {}) ⇒ Object
11
12
13
14
15
|
# File 'lib/schemagraphy/cfgyml/doc_builder.rb', line 11
def call schema, options = {}
pretty = options.fetch(:pretty, true)
data = reference_hash(schema)
pretty ? JSON.pretty_generate(data) : JSON.generate(data)
end
|
.reference_hash(schema) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/schemagraphy/cfgyml/doc_builder.rb', line 17
def reference_hash schema
{
'format' => 'releasehx-config-reference',
'version' => 1,
'properties' => build_properties(schema['properties'], [])
}
end
|