Class: Synthra::Export::Base Abstract
- Inherits:
-
Object
- Object
- Synthra::Export::Base
- Defined in:
- lib/synthra/export/base.rb
Overview
Subclass and implement #export to create an exporter
Base class for all exporters
Provides common functionality for exporting schemas to different formats.
Direct Known Subclasses
Csv, Graphql, Graphviz, Javascript, JsonData, JsonSchema, Python, Sql, SqlInsert, Typescript, XmlData, YamlData
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
Export options.
-
#registry ⇒ Registry
readonly
The registry for resolving references.
-
#schema ⇒ Schema
readonly
The schema to export.
Instance Method Summary collapse
-
#all_fields ⇒ Array<Field>
protected
Get all fields including from nested schemas.
-
#export ⇒ String
abstract
Export the schema to the target format.
-
#get_schema(type_name) ⇒ Schema?
protected
Get referenced schema.
-
#initialize(schema, registry: nil, **options) ⇒ Base
constructor
Create a new exporter.
-
#save(path) ⇒ void
Save export to a file.
-
#schema_reference?(type_name) ⇒ Boolean
protected
Check if a type is a schema reference.
Constructor Details
#initialize(schema, registry: nil, **options) ⇒ Base
Create a new exporter
28 29 30 31 32 |
# File 'lib/synthra/export/base.rb', line 28 def initialize(schema, registry: nil, **) @schema = schema @registry = registry @options = end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns export options.
20 21 22 |
# File 'lib/synthra/export/base.rb', line 20 def @options end |
#registry ⇒ Registry (readonly)
Returns the registry for resolving references.
17 18 19 |
# File 'lib/synthra/export/base.rb', line 17 def registry @registry end |
#schema ⇒ Schema (readonly)
Returns the schema to export.
14 15 16 |
# File 'lib/synthra/export/base.rb', line 14 def schema @schema end |
Instance Method Details
#all_fields ⇒ Array<Field> (protected)
Get all fields including from nested schemas
58 59 60 |
# File 'lib/synthra/export/base.rb', line 58 def all_fields schema.fields end |
#export ⇒ String
Export the schema to the target format
39 40 41 |
# File 'lib/synthra/export/base.rb', line 39 def export raise NotImplementedError, "Subclasses must implement #export" end |
#get_schema(type_name) ⇒ Schema? (protected)
Get referenced schema
76 77 78 79 80 |
# File 'lib/synthra/export/base.rb', line 76 def get_schema(type_name) registry&.schema(type_name) rescue KeyError nil # schema not found end |
#save(path) ⇒ void
This method returns an undefined value.
Save export to a file
48 49 50 |
# File 'lib/synthra/export/base.rb', line 48 def save(path) File.write(path, export) end |
#schema_reference?(type_name) ⇒ Boolean (protected)
Check if a type is a schema reference
67 68 69 |
# File 'lib/synthra/export/base.rb', line 67 def schema_reference?(type_name) registry&.schema?(type_name) || false end |