Appearance
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.ymlThis 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::ControllerGeneratorLoci 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: falseAccessing 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
# => falseConfiguration 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_formatThis allows:
- Sensible project-wide defaults
- CLI overrides when needed
- Zero duplication between config and generator logic