Class: EcsRails::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
lib/generators/ecs_rails/install/install_generator.rb

Overview

rails g ecs_rails:install

Implements RFC-0008. Emits the entities migration and the two abstract base classes a host app subclasses from. The migration mirrors docs/architecture.md §2 exactly — if the two ever disagree, the architecture document wins.

Inherits from Base rather than NamedBase: install takes no NAME argument.

Instance Method Summary collapse

Instance Method Details

#create_base_modelsObject

ADR-0010: base classes land under the configured layout — ApplicationEntity at entities_path, ApplicationComponent at components_path (entities_path/components).



57
58
59
60
61
62
# File 'lib/generators/ecs_rails/install/install_generator.rb', line 57

def create_base_models
  template "application_entity.rb.tt",
           File.join(EcsRails.config.entities_path, "application_entity.rb")
  template "application_component.rb.tt",
           File.join(EcsRails.config.components_path, "application_component.rb")
end

#create_initializerObject

ADR-0010: the generated initializer both records the chosen layout (so ecs_rails:component and the app agree on it) and collapses the nested components directory, so Zeitwerk maps app/entities/components/name.rb to the top-level Name rather than Components::Name.

An initializer — not application.rb, not the gem’s Railtie — is the right home for the collapse: it runs before eager_load under both lazy and eager modes, and it does not read entities_path before app initializers have had their chance to set it. See ADR-0010 “How it works”.



73
74
75
# File 'lib/generators/ecs_rails/install/install_generator.rb', line 73

def create_initializer
  template "initializer.rb.tt", "config/initializers/ecs_rails.rb"
end

#create_migration_file

This method returns an undefined value.

Emits the entities table migration.

A Thor task: invoked as a generator step, not called directly.



47
48
49
50
51
52
# File 'lib/generators/ecs_rails/install/install_generator.rb', line 47

def create_migration_file
  migration_template(
    "migration.rb.tt",
    File.join(db_migrate_path, "ecs_rails_create_entities.rb")
  )
end