Skip to content

User Configuration File ​

Loci supports user-level configuration through a dedicated YAML file. This is especially useful when sharing the same pack of generators across multiple projects. Also improves options discoverability.

Location and Purpose ​

The configuration file lives at project root level in:

bash
.generators.yml

This file is:

  • User-owned – intended for project or developer customization
  • Centralized – all generator configuration in one place
  • Declarative – no Ruby required

Key Lookup ​

For a generator named:

ruby
Rails::Backend::ControllerGenerator

Loci looks for configuration under:

yaml
rails:
  backend:
    controller:

This mapping is automatic and convention-based.

Example .generators.yml ​

Example configuration for Rails::Backend::ControllerGenerator

yaml
rails:
  backend:
    controller:
      api_only: true
      default_format: json
      skip_routes: false

Accessing Configuration ​

Configuration is exposed via the config available at both class and instance level.

ruby
config.api_only
# => true

config.default_format
# => "json"

self.config.skip_routes
# => false

Configuration Shape ​

Given the YAML above, config resolves to:

ruby
config.to_h
# => {
#   api_only: true,
#   default_format: "json",
#   skip_routes: false
# }

Using Configuration as Option Defaults ​

A common and encouraged pattern is to use configuration values as defaults for generator options.

ruby
option :format, default: config.default_format

This allows:

  • Sensible project-wide defaults
  • CLI overrides when needed
  • Zero duplication between config and generator logic