Skip to content

Add configurable defaults for rails-new - #65

Open
Retasusan wants to merge 1 commit into
rails:mainfrom
Retasusan:configurable-defaults
Open

Retasusan wants to merge 1 commit into
rails:mainfrom
Retasusan:configurable-defaults

Conversation

@Retasusan

Copy link
Copy Markdown

Summary

Add support for configuring default Ruby and Rails versions, along with reusable rails new arguments, through a TOML configuration file.

Motivation

Users who consistently generate applications with the same Ruby version, Rails version, or rails new options currently need to repeat those flags for every
invocation.

This change allows those defaults to be stored in:

~/.config/rails-new/config.toml

When XDG_CONFIG_HOME is set, rails-new reads:

XDG_CONFIG_HOME/rails-new/config.toml

On Windows, it falls back to:

%APPDATA%\rails-new\config.toml

Example

# toml:config.toml
ruby_version = "3.3.0"
rails_version = "8.0.0"

rails_args = [
  "--database=postgresql",
  "--skip-test",
  "--skip-system-test",
]

With this configuration:

rails-new myapp

uses the configured Ruby and Rails versions and passes the configured arguments to rails new.

Explicit command-line values take precedence over configured defaults:

$ rails-new --ruby-version 3.4.0 myapp --database=sqlite3

Configured rails_args are inserted after the application path and before additional command-line arguments.

If the configuration file does not exist, the existing behavior is preserved:

  • the latest Ruby version is used
  • the latest Rails version is installed
  • only command-line arguments are passed to rails new

Unknown configuration keys and invalid TOML produce an actionable error instead of being silently ignored.

Validation

  • cargo test --locked — 22 tests passed
  • Generated a Rails application through Docker using configured --skip-test, --skip-system-test, --skip-git, and --skip-bundle arguments
  • Verified that test/, .git/, and Gemfile.lock were not generated
  • Verified that the generated application was written to the host filesystem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant