forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This command boots the application, and generates a Dev Container setup based on the current configuration of the application.
- Loading branch information
1 parent
1f4bedc
commit 67d55c2
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
railties/lib/rails/commands/devcontainer/devcontainer_command.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails/generators" | ||
require "rails/generators/rails/devcontainer/devcontainer_generator" | ||
|
||
module Rails | ||
module Command | ||
class DevcontainerCommand < Base # :nodoc: | ||
desc "devcontainer", "Generate a Dev Container setup based on current application configuration" | ||
def perform(*) | ||
boot_application! | ||
|
||
say "Generating Dev Container with the following options:" | ||
devcontainer_options.each do |option, value| | ||
say "#{option}: #{value}" | ||
end | ||
|
||
Rails::Generators::DevcontainerGenerator.new([], devcontainer_options).invoke_all | ||
end | ||
|
||
private | ||
def devcontainer_options | ||
@devcontainer_options ||= { | ||
app_name: Rails.application.railtie_name.chomp("_application"), | ||
database: !!defined?(ActiveRecord) && ActiveRecord::Base.connection_db_config.adapter, | ||
active_storage: !!defined?(ActiveStorage), | ||
redis: !!(defined?(ActionCable) || defined?(ActiveJob)), | ||
system_test: File.exist?("test/application_system_test_case.rb"), | ||
node: File.exist?(".node-version"), | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require "isolation/abstract_unit" | ||
require "rails/command" | ||
|
||
class Rails::Command::DevcontainerTest < ActiveSupport::TestCase | ||
include ActiveSupport::Testing::Isolation | ||
|
||
teardown { teardown_app } | ||
|
||
test "generates devcontainer for default app" do | ||
build_app | ||
|
||
output = rails "devcontainer" | ||
|
||
assert_match "app_name: app_template", output | ||
assert_match "database: sqlite3", output | ||
assert_match "active_storage: true", output | ||
assert_match "redis: true", output | ||
assert_match "system_test: true", output | ||
assert_match "node: false", output | ||
end | ||
end |