Class: YamlExporter::Schema
- Inherits:
-
Object
- Object
- YamlExporter::Schema
- Defined in:
- lib/yaml_exporter/schema.rb
Overview
Builds a JSON-schema-ish hash describing a structure. Keys are symbols
so callers can use schema[:properties][:title] ergonomically.
Class Method Summary collapse
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(structure) ⇒ Schema
constructor
A new instance of Schema.
Constructor Details
#initialize(structure) ⇒ Schema
Returns a new instance of Schema.
11 12 13 |
# File 'lib/yaml_exporter/schema.rb', line 11 def initialize(structure) @structure = structure end |
Class Method Details
.generate(structure) ⇒ Object
7 8 9 |
# File 'lib/yaml_exporter/schema.rb', line 7 def self.generate(structure) new(structure).generate end |
Instance Method Details
#generate ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/yaml_exporter/schema.rb', line 15 def generate { type: 'object', properties: @structure.nodes.each_with_object({}) do |node, acc| acc.merge!(node.schema_fragment) end } end |