Class: Typelizer::Writer
- Inherits:
-
Object
- Object
- Typelizer::Writer
- Defined in:
- lib/typelizer/writer.rb
Defined Under Namespace
Classes: WriterError
Instance Method Summary collapse
- #call(interfaces, force:) ⇒ Object
-
#initialize(config) ⇒ Writer
constructor
A new instance of Writer.
Constructor Details
#initialize(config) ⇒ Writer
Returns a new instance of Writer.
9 10 11 12 |
# File 'lib/typelizer/writer.rb', line 9 def initialize(config) @template_cache = {} @config = config end |
Instance Method Details
#call(interfaces, force:) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/typelizer/writer.rb', line 14 def call(interfaces, force:) cleanup_output_dir(interfaces) if force valid_interfaces = interfaces.reject(&:empty?) return [] if valid_interfaces.empty? written_files = [] begin written_files.concat(valid_interfaces.map { |interface| write_interface(interface) }) enums = collect_enums(valid_interfaces) written_files << write_enums(enums) if enums.any? written_files << write_index(valid_interfaces, enums: enums) cleanup_stale_files(written_files, valid_interfaces) unless force Typelizer.logger.debug("Generated #{written_files.size} TypeScript files in #{config.output_dir}") written_files rescue => e # if during the file generations an error appears, we remove generated files cleanup_partial_writes(written_files) raise WriterError, "Failed to write TypeScript files (#{e.class}): #{e.}" end end |