Class: Rails::Generators::DevcontainerGenerator
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Base ,
Thor::Group
|
|
Instance Chain:
|
|
Inherits: |
Rails::Generators::Base
|
Defined in: | railties/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb |
Class Attribute Summary
Base
- Inherited
Class Method Summary
Base
- Inherited
.base_root | Returns the base root for a common set of generators. |
.default_source_root | Returns the default source root for a given generator. |
.desc | Tries to get the description from a USAGE file one folder above the source root otherwise uses a default description. |
.hide! | Convenience method to hide this generator from the available ones when running rails generator command. |
.hook_for | Invoke a generator based on the value supplied by the user to the given option named “name”. |
.namespace | Convenience method to get the namespace from the class name. |
.remove_hook_for | Remove a previously added hook. |
.source_root | Returns the source root for this generator using default_source_root as default. |
.add_shebang_option! | Small macro to add ruby as an option to the generator with proper default value plus an instance helper method called shebang. |
.banner | Use Rails default banner. |
.base_name | Sets the base_name taking into account the current class namespace. |
.default_aliases_for_option | Returns default aliases for the option name given doing a lookup in aliases. |
.default_for_option | Returns default for the option name given doing a lookup in config. |
.default_generator_root, | |
.default_value_for_option | Returns the default value for the option name given doing a lookup in options. |
.generator_name | Removes the namespaces and get the generator name. |
.usage_path, | |
.class_option | |
.inherited | Cache source root and add lib/generators/base/generator/templates to source paths. |
.hooks | Keep hooks configuration that are used on prepare_for_invocation. |
.prepare_for_invocation | Prepare class invocation to search on |
Instance Attribute Summary
Instance Method Summary
- #create_devcontainer
- #update_application_system_test_case
- #update_database_yml
- #app_name private
- #container_env private
- #database private
- #dependencies private
- #devcontainer_db_service_yaml(**options) private
- #features private
- #forward_ports private
- #local_rails_mount private
- #mounts private
- #system_test_configuration private
- #volumes private
Base
- Inherited
#class_collisions | Check whether the given class names are already taken by user application or Ruby on |
#extract_last_module | Takes in an array of nested modules and extracts the last module. |
#indent, | |
#module_namespacing | Wrap block with namespace of current application if namespace exists and is not skipped. |
#namespace, #namespace_dirs, #namespaced_path, #wrap_with_namespace |
Actions
- Included
#add_source | Add the given source to |
#application | Alias for Actions#environment. |
#environment | Adds configuration code to a Rails runtime environment. |
#gem | Adds a |
#gem_group | Wraps gem entries inside a group. |
#generate | Runs another generator. |
#git | Runs one or more git commands. |
#github, | |
#initializer | Creates an initializer file in |
#lib | Creates a file in |
#rails_command | Runs the specified Rails command. |
#rake | Runs the specified Rake task. |
#rakefile | Creates a Rake tasks file in |
#readme | Reads the given file at the source root and prints it in the console. |
#route | Make an entry in Rails routing file |
#vendor | Creates a file in |
#append_file_with_newline | Append string to a file with a newline if necessary. |
#execute_command | Runs the supplied command using either “rake …” or “rails …” based on the executor parameter provided. |
#indentation | Indent the |
#log | Define log for backwards compatibility. |
#match_file, | |
#optimize_indentation | Returns optimized string with indentation. |
#quote | Always returns value in double quotes. |
#rebase_indentation | Alias for Actions#optimize_indentation. |
#route_namespace_pattern, | |
#with_indentation | Manage |
#initialize |
Instance Attribute Details
#devcontainer? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb', line 62
def devcontainer? true end
Instance Method Details
#app_name (private)
[ GitHub ]# File 'railties/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb', line 66
def app_name [:app_name] end
#container_env (private)
[ GitHub ]# File 'railties/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb', line 81
def container_env return @container_env if @container_env @container_env = {} @container_env["CAPYBARA_SERVER_PORT"] = "45678" if [:system_test] @container_env["SELENIUM_HOST"] = "selenium" if [:system_test] @container_env["REDIS_URL"] = "redis://redis:6379/1" if [:redis] @container_env["KAMAL_REGISTRY_PASSWORD"] = "$KAMAL_REGISTRY_PASSWORD" if [:kamal] @container_env["DB_HOST"] = database.name if database.service @container_env end
#create_devcontainer
[ GitHub ]# File 'railties/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb', line 37
def create_devcontainer empty_directory ".devcontainer" template "devcontainer/devcontainer.json", ".devcontainer/devcontainer.json" template "devcontainer/Dockerfile", ".devcontainer/Dockerfile" template "devcontainer/compose.yaml", ".devcontainer/compose.yaml" end
#database (private)
[ GitHub ]#dependencies (private)
[ GitHub ]# File 'railties/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb', line 70
def dependencies return @dependencies if @dependencies @dependencies = [] @dependencies << "selenium" if [:system_test] @dependencies << "redis" if [:redis] @dependencies << database.name if database.service @dependencies end
#devcontainer_db_service_yaml(**options) (private)
[ GitHub ]#features (private)
[ GitHub ]# File 'railties/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb', line 106
def features return @features if @features @features = { "ghcr.io/devcontainers/features/github-cli:1" => {} } @features["ghcr.io/rails/devcontainer/features/activestorage"] = {} if [:active_storage] @features["ghcr.io/devcontainers/features/node:1"] = {} if [:node] @features["ghcr.io/devcontainers/features/docker-outside-of-docker:1"] = {} if [:kamal] @features.merge!(database.feature) if database.feature @features end
#forward_ports (private)
[ GitHub ]#local_rails_mount (private)
[ GitHub ]# File 'railties/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb', line 152
def local_rails_mount { type: "bind", source: Rails::Generators::RAILS_DEV_PATH, target: Rails::Generators::RAILS_DEV_PATH } end
#mounts (private)
[ GitHub ]# File 'railties/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb', line 122
def mounts return @mounts if @mounts @mounts = [] @mounts << local_rails_mount if [:dev] @mounts end
#system_test_configuration (private)
[ GitHub ]# File 'railties/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb', line 160
def system_test_configuration optimize_indentation(<<-'RUBY', 2).chomp if ENV["CAPYBARA_SERVER_PORT"] served_by host: "rails-app", port: ENV["CAPYBARA_SERVER_PORT"] driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ], options: { browser: :remote, url: "http://#{ENV["SELENIUM_HOST"]}:4444" } else driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ] end RUBY end
#update_application_system_test_case
[ GitHub ]# File 'railties/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb', line 45
def update_application_system_test_case return unless [:system_test] system_test_case_path = File. "test/application_system_test_case.rb", destination_root return unless File.exist? system_test_case_path gsub_file(system_test_case_path, /^\s*driven_by\b.*/, system_test_configuration) end
#update_database_yml
[ GitHub ]# File 'railties/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb', line 54
def update_database_yml # Only postgresql has devcontainer specific configuration, so only update database.yml if we are using postgres return unless [:database] == "postgresql" template("config/databases/#{ [:database]}.yml", "config/database.yml") end