Class: Zodra::Export::Writer
- Inherits:
-
Object
- Object
- Zodra::Export::Writer
- Defined in:
- lib/zodra/export/writer.rb
Constant Summary collapse
- HEADER =
'// Auto-generated by Zodra — DO NOT EDIT'- FORMATS =
{ zod: 'schemas.ts', typescript: 'types.ts' }.freeze
Instance Method Summary collapse
-
#initialize(configuration) ⇒ Writer
constructor
A new instance of Writer.
- #write(format) ⇒ Object
- #write_all ⇒ Object
- #write_contracts ⇒ Object
Constructor Details
#initialize(configuration) ⇒ Writer
Returns a new instance of Writer.
15 16 17 |
# File 'lib/zodra/export/writer.rb', line 15 def initialize(configuration) @configuration = configuration end |
Instance Method Details
#write(format) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/zodra/export/writer.rb', line 19 def write(format) content = Export.generate(format, key_format: @configuration.key_format, zod_import: @configuration.zod_import) write_file(FORMATS.fetch(format), content) end |
#write_all ⇒ Object
34 35 36 37 38 39 |
# File 'lib/zodra/export/writer.rb', line 34 def write_all paths = FORMATS.keys.map { |format| write(format) } contracts_path = write_contracts paths << contracts_path if contracts_path paths end |
#write_contracts ⇒ Object
27 28 29 30 31 32 |
# File 'lib/zodra/export/writer.rb', line 27 def write_contracts content = Export.generate_contracts return if content.empty? write_file('contracts.ts', content) end |