File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
lib/rails/commands/devcontainer Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+ require "rails/generators/rails/devcontainer/devcontainer_generator"
5
+
6
+ module Rails
7
+ module Command
8
+ class DevcontainerCommand < Base # :nodoc:
9
+ desc "devcontainer" , "Generate a Dev Container setup based on current application configuration"
10
+ def perform ( *)
11
+ boot_application!
12
+
13
+ say "Generating Dev Container with the following options:"
14
+ devcontainer_options . each do |option , value |
15
+ say "#{ option } : #{ value } "
16
+ end
17
+
18
+ Rails ::Generators ::DevcontainerGenerator . new ( [ ] , devcontainer_options ) . invoke_all
19
+ end
20
+
21
+ private
22
+ def devcontainer_options
23
+ @devcontainer_options ||= {
24
+ app_name : Rails . application . railtie_name . chomp ( "_application" ) ,
25
+ database : !!defined? ( ActiveRecord ) && ActiveRecord ::Base . connection_db_config . adapter ,
26
+ active_storage : !!defined? ( ActiveStorage ) ,
27
+ redis : !!( defined? ( ActionCable ) || defined? ( ActiveJob ) ) ,
28
+ system_test : File . exist? ( "test/application_system_test_case.rb" ) ,
29
+ node : File . exist? ( ".node-version" ) ,
30
+ }
31
+ end
32
+ end
33
+ end
34
+ end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "isolation/abstract_unit"
4
+ require "rails/command"
5
+
6
+ class Rails ::Command ::DevcontainerTest < ActiveSupport ::TestCase
7
+ include ActiveSupport ::Testing ::Isolation
8
+
9
+ teardown { teardown_app }
10
+
11
+ test "generates devcontainer for default app" do
12
+ build_app
13
+
14
+ output = rails "devcontainer"
15
+
16
+ assert_match "app_name: app_template" , output
17
+ assert_match "database: sqlite3" , output
18
+ assert_match "active_storage: true" , output
19
+ assert_match "redis: true" , output
20
+ assert_match "system_test: true" , output
21
+ assert_match "node: false" , output
22
+ end
23
+ end
You can’t perform that action at this time.
0 commit comments