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 =

Returns:

  • (Array<Symbol>)
%i(record enum).freeze
INITIALIZE_WHITESPACE =

Returns:

  • (String)
"\n#{' ' * 19}"
IGNORE_DEFAULTS =

Returns:

  • (Array<String>)
%w(message_id timestamp).freeze
SCHEMA_CLASS_FILE =

Returns:

  • (String)
'schema_class.rb'
SCHEMA_RECORD_PATH =

Returns:

  • (String)
File.expand_path('schema_class/templates/schema_record.rb.tt', __dir__).freeze
SCHEMA_ENUM_PATH =

Returns:

  • (String)
File.expand_path('schema_class/templates/schema_enum.rb.tt', __dir__).freeze

Instance Method Summary collapse

Instance Method Details

#generatevoid

This method returns an undefined value.



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/generators/deimos/schema_class_generator.rb', line 163

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, config.key_config)
  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, config.key_config)
  end

  generate_from_schema_files(found_schemas)

end