Class: Deimos::Generators::SchemaClassGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/deimos/schema_class_generator.rb

Overview

Generator for Schema Classes used for the IDE and consumer/producer interfaces

Constant Summary collapse

SPECIAL_TYPES =
%i(record enum).freeze
INITIALIZE_WHITESPACE =
"\n#{' ' * 19}"
IGNORE_DEFAULTS =
%w(message_id timestamp).freeze
SCHEMA_CLASS_FILE =
'schema_class.rb'
SCHEMA_RECORD_PATH =
File.expand_path('schema_class/templates/schema_record.rb.tt', __dir__).freeze
SCHEMA_ENUM_PATH =
File.expand_path('schema_class/templates/schema_enum.rb.tt', __dir__).freeze

Instance Method Summary collapse

Instance Method Details

#generateObject

:nodoc:



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/generators/deimos/schema_class_generator.rb', line 151

def generate
  _validate
  Rails.logger.info("Generating schemas from Deimos.config to #{Deimos.config.schema.generated_class_path}")
  found_schemas = Set.new
  Deimos.config.producer_objects.each do |config|
    schema_name = config.schema
    namespace = config.namespace || Deimos.config.producers.schema_namespace
    key_schema_name = config.key_config[:schema]
    found_schemas.add("#{namespace}.#{schema_name}")
    found_schemas.add("#{namespace}.#{key_schema_name}") if key_schema_name
    generate_classes(schema_name, namespace, key_schema_name)
  end

  Deimos.config.consumer_objects.each do |config|
    schema_name = config.schema
    namespace = config.namespace
    key_schema_name = config.key_config[:schema]
    found_schemas.add("#{namespace}.#{schema_name}")
    found_schemas.add("#{namespace}.#{key_schema_name}") if key_schema_name
    generate_classes(schema_name, namespace, key_schema_name)
  end

  generate_from_schema_files(found_schemas)

end