Class: Rails::Generators::AppGenerator
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
Rails::Generators::AppBase
|
Defined in: | railties/lib/rails/generators/rails/app/app_generator.rb, railties/lib/rails/commands/application/application_command.rb |
Constant Summary
-
META_OPTIONS =
Internal use only
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 322[:minimal]
-
OPTION_IMPLICATIONS =
Internal use only
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 297AppBase::OPTION_IMPLICATIONS.merge( skip_git: [:skip_decrypted_diffs], minimal: [ :skip_action_cable, :skip_action_mailbox, :skip_action_mailer, :skip_action_text, :skip_active_job, :skip_active_storage, :skip_bootsnap, :skip_dev_gems, :skip_hotwire, :skip_javascript, :skip_jbuilder, :skip_system_test, ], api: [ :skip_asset_pipeline, :skip_javascript, ], ) do |option, implications, more_implications| implications + more_implications end
AppName
- Included
AppBase
- Inherited
BUN_VERSION, CSS_OPTIONS, JAVASCRIPT_OPTIONS, NODE_LTS_VERSION, OPTION_IMPLICATIONS
Class Attribute Summary
-
.exit_on_failure? ⇒ Boolean
readonly
Internal use only
We want to exit on failure to be kind to other libraries This is only when accessing via CLI.
Base
- Inherited
Class Method Summary
- .apply_rails_template(template, destination) Internal use only
- .banner Internal use only
- .new(*args) ⇒ AppGenerator constructor Internal use only
AppBase
- Inherited
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
AppBase
- Inherited
AppName
- Included
Base
- Inherited
Instance Method Summary
-
#after_bundle(&block)
private
Registers a callback to be executed after bundle binstubs have run.
-
#file(*args, &block)
private
Define file as an alias to create_file for backwards compatibility.
- #get_builder_class private
- #create_active_record_files Internal use only
- #create_app_files Internal use only
- #create_bin_files Internal use only
- #create_boot_file Internal use only
- #create_cifiles Internal use only
- #create_config_files Internal use only
- #create_credentials Internal use only
- #create_db_files Internal use only
- #create_devcontainer_files Internal use only
- #create_dockerfiles Internal use only
- #create_lib_files Internal use only
- #create_log_files Internal use only
- #create_master_key Internal use only
- #create_public_files Internal use only
- #create_root_files Internal use only
- #create_rubocop_file Internal use only
- #create_script_folder Internal use only
- #create_storage_files Internal use only
- #create_system_test_files Internal use only
- #create_test_files Internal use only
- #create_tmp_files Internal use only
- #create_vendor_files Internal use only
- #delete_action_cable_files_skipping_action_cable Internal use only
- #delete_action_mailer_files_skipping_action_mailer Internal use only
- #delete_active_job_folder_if_skipping_active_job Internal use only
- #delete_api_initializers Internal use only
- #delete_app_assets_if_api_option Internal use only
- #delete_app_helpers_if_api_option Internal use only
- #delete_app_views_if_api_option Internal use only
- #delete_application_record_skipping_active_record Internal use only
- #delete_assets_initializer_skipping_asset_pipeline Internal use only
- #delete_new_framework_defaults Internal use only
- #delete_non_api_initializers_if_api_option Internal use only
- #delete_public_files_if_api_option Internal use only
- #finish_template Internal use only
- #run_after_bundle_callbacks Internal use only
- #update_active_storage Internal use only
- #update_bin_files Internal use only
- #update_config_files Internal use only
AppBase
- Inherited
AppName
- Included
#app_const, #app_const_base, #app_name, | |
#camelized | Alias for AppName#app_const_base. |
#original_app_name |
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 |
Constructor Details
.new(*args) ⇒ AppGenerator
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 332
def initialize(*args) super (OPTION_IMPLICATIONS, meta_options: META_OPTIONS) @after_bundle_callbacks = [] end
Class Attribute Details
.exit_on_failure? ⇒ Boolean
(readonly)
We want to exit on failure to be kind to other libraries This is only when accessing via CLI
# File 'railties/lib/rails/commands/application/application_command.rb', line 11
def self.exit_on_failure? true end
Class Method Details
.apply_rails_template(template, destination)
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 324
def self.apply_rails_template(template, destination) # :nodoc: generator = new([destination], { template: template }, { destination_root: destination }) generator.set_default_accessors! generator.apply_rails_template generator.run_bundle generator.run_after_bundle_callbacks end
.banner
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 577
def self. "rails new #{arguments.map(&:usage).join(' ')} [options]" end
Instance Method Details
#after_bundle(&block) (private)
Registers a callback to be executed after bundle binstubs have run.
after_bundle do
git add: '.'
end
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 595
def after_bundle(&block) # :doc: @after_bundle_callbacks << block end
#create_active_record_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 418
def create_active_record_files return if [:skip_active_record] build(:database_yml) end
#create_app_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 361
def create_app_files build(:app) end
#create_bin_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 365
def create_bin_files build(:bin) end
#create_boot_file
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 414
def create_boot_file template "config/boot.rb" end
#create_cifiles
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 391
def create_cifiles return if skip_ci? build(:cifiles) end
#create_config_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 396
def create_config_files build(:config) end
#create_credentials
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 409
def create_credentials build(:credentials) build(:credentials_diff_enroll) end
#create_db_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 423
def create_db_files return if [:skip_active_record] build(:db) end
#create_devcontainer_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 465
def create_devcontainer_files return if skip_devcontainer? || [:dummy_app] build(:devcontainer) end
#create_dockerfiles
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 381
def create_dockerfiles return if [:skip_docker] || [:dummy_app] build(:dockerfiles) end
#create_lib_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 428
def create_lib_files build(:lib) end
#create_log_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 432
def create_log_files build(:log) end
#create_master_key
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 405
def create_master_key build(:master_key) end
#create_public_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 436
def create_public_files build(:public_directory) end
#create_root_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 345
def create_root_files build(:readme) build(:rakefile) build(:node_version) if using_node? build(:ruby_version) build(:configru) unless [:skip_git] build(:gitignore) build(:gitattributes) end build(:gemfile) build(:version_control) end
#create_rubocop_file
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 386
def create_rubocop_file return if skip_rubocop? build(:rubocop) end
#create_script_folder
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 440
def create_script_folder return if [:dummy_app] build(:script) end
#create_storage_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 461
def create_storage_files build(:storage) unless skip_storage? end
#create_system_test_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 457
def create_system_test_files build(:system_test) if depends_on_system_test? end
#create_test_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 453
def create_test_files build(:test) unless [:skip_test] end
#create_tmp_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 445
def create_tmp_files build(:tmp) end
#create_vendor_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 449
def create_vendor_files build(:vendor) end
#delete_action_cable_files_skipping_action_cable
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 535
def delete_action_cable_files_skipping_action_cable if [:skip_action_cable] remove_dir "app/javascript/channels" end end
#delete_action_mailer_files_skipping_action_mailer
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 526
def delete_action_mailer_files_skipping_action_mailer if [:skip_action_mailer] remove_file "app/views/layouts/mailer.html.erb" remove_file "app/views/layouts/mailer.text.erb" remove_dir "app/mailers" remove_dir "test/mailers" end end
#delete_active_job_folder_if_skipping_active_job
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 520
def delete_active_job_folder_if_skipping_active_job if [:skip_active_job] remove_dir "app/jobs" end end
#delete_api_initializers
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 547
def delete_api_initializers unless [:api] remove_file "config/initializers/cors.rb" end end
#delete_app_assets_if_api_option
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 470
def delete_app_assets_if_api_option if [:api] remove_dir "app/assets" end end
#delete_app_helpers_if_api_option
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 476
def delete_app_helpers_if_api_option if [:api] remove_dir "app/helpers" remove_dir "test/helpers" end end
#delete_app_views_if_api_option
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 483
def delete_app_views_if_api_option if [:api] if [:skip_action_mailer] remove_dir "app/views" else remove_file "app/views/layouts/application.html.erb" remove_dir "app/views/pwa" end end end
#delete_application_record_skipping_active_record
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 514
def delete_application_record_skipping_active_record if [:skip_active_record] remove_file "app/models/application_record.rb" end end
#delete_assets_initializer_skipping_asset_pipeline
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 506
def delete_assets_initializer_skipping_asset_pipeline if skip_asset_pipeline? remove_file "config/initializers/assets.rb" remove_file "app/assets/stylesheets/application.css" create_file "app/assets/stylesheets/application.css", "/* Application styles */\n" unless [:api] end end
#delete_new_framework_defaults
#delete_non_api_initializers_if_api_option
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 541
def delete_non_api_initializers_if_api_option if [:api] remove_file "config/initializers/content_security_policy.rb" end end
#delete_public_files_if_api_option
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 494
def delete_public_files_if_api_option if [:api] remove_file "public/400.html" remove_file "public/404.html" remove_file "public/406-unsupported-browser.html" remove_file "public/422.html" remove_file "public/500.html" remove_file "public/icon.png" remove_file "public/icon.svg" end end
#file(*args, &block) (private)
Define file as an alias to create_file for backwards compatibility.
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 585
def file(*args, &block) create_file(*args, &block) end
#finish_template
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 559
def finish_template build(:leftovers) end
#get_builder_class (private)
[ GitHub ]# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 599
def get_builder_class defined?(::AppBuilder) ? ::AppBuilder : Rails::AppBuilder end
#run_after_bundle_callbacks
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 573
def run_after_bundle_callbacks @after_bundle_callbacks.each(&:call) end
#update_active_storage
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 374
def update_active_storage unless skip_active_storage? rails_command "active_storage:update", inline: true end end
#update_bin_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 369
def update_bin_files build(:bin_when_updating) end
#update_config_files
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 400
def update_config_files build(:config_when_updating) end