Class: Rails::Generators::AppBase
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Base ,
Thor::Group
|
|
Instance Chain:
|
|
Inherits: |
Rails::Generators::Base
|
Defined in: | railties/lib/rails/generators/app_base.rb |
Constant Summary
-
BUN_VERSION =
# File 'railties/lib/rails/generators/app_base.rb', line 18"1.0.1"
-
CSS_OPTIONS =
# File 'railties/lib/rails/generators/app_base.rb', line 21%w( tailwind bootstrap bulma postcss sass )
-
JAVASCRIPT_OPTIONS =
# File 'railties/lib/rails/generators/app_base.rb', line 20%w( importmap bun webpack esbuild rollup )
-
NODE_LTS_VERSION =
# File 'railties/lib/rails/generators/app_base.rb', line 17"20.11.1"
-
OPTION_IMPLICATIONS =
# File 'railties/lib/rails/generators/app_base.rb', line 202{ # :nodoc: skip_active_job: [:skip_action_mailer, :skip_active_storage], skip_active_record: [:skip_active_storage, :skip_solid], skip_active_storage: [:skip_action_mailbox, :skip_action_text], skip_javascript: [:skip_hotwire], }
AppName
- Included
Class Attribute Summary
Base
- Inherited
Class Method Summary
- .add_shared_options_for(name)
- .edge_branch
- .new(positional_argv, option_argv) ⇒ AppBase constructor
- .strict_args_position
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
- #bundle_install? ⇒ Boolean readonly
- #depend_on_bootsnap? ⇒ Boolean readonly
- #depends_on_system_test? ⇒ Boolean readonly
- #rails_prerelease? ⇒ Boolean readonly
- #rails_template rw
- #using_bun? ⇒ Boolean readonly
- #using_js_runtime? ⇒ Boolean readonly
- #using_node? ⇒ Boolean readonly
- #devcontainer? ⇒ Boolean readonly private
- #include_all_railties? ⇒ Boolean readonly private
- #keeps? ⇒ Boolean readonly private
- #skip_action_cable? ⇒ Boolean readonly private
- #skip_action_mailbox? ⇒ Boolean readonly private
- #skip_action_mailer? ⇒ Boolean readonly private
- #skip_action_text? ⇒ Boolean readonly private
- #skip_active_record? ⇒ Boolean readonly private
- #skip_active_storage? ⇒ Boolean readonly private
- #skip_asset_pipeline? ⇒ Boolean readonly private
- #skip_brakeman? ⇒ Boolean readonly private
- #skip_ci? ⇒ Boolean readonly private
- #skip_devcontainer? ⇒ Boolean readonly private
- #skip_kamal? ⇒ Boolean readonly private
- #skip_rubocop? ⇒ Boolean readonly private
- #skip_solid? ⇒ Boolean readonly private
- #skip_storage? ⇒ Boolean readonly private
- #skip_thruster? ⇒ Boolean readonly private
- #sqlite3? ⇒ Boolean readonly private
AppName
- Included
Base
- Inherited
Instance Method Summary
- #add_bundler_platforms
- #bundle_command(command, env = {})
- #cable_gemfile_entry
- #ci_packages
- #css_gemfile_entry
- #database
- #dockerfile_base_packages
- #dockerfile_binfile_fixups
- #dockerfile_build_packages
- #dockerfile_bun_version
- #dockerfile_chown_directories
- #dockerfile_yarn_version
- #edge_branch
- #empty_directory_with_keep_file(destination, config = {})
- #exec_bundle_command(bundle_command, command, env)
- #generate_bundler_binstub
- #git_init_command
- #hotwire_gemfile_entry
- #javascript_gemfile_entry
- #jbuilder_gemfile_entry
- #keep_file(destination)
- #node_version
- #rails_gemfile_entry
- #rails_version_specifier(gem_version = Rails.gem_version)
- #run_bundle
- #run_css
- #run_hotwire
- #run_javascript
- #run_kamal
- #run_solid
- #target_rails_prerelease(self_command = "new")
- #user_default_branch
- #apply_rails_template private
- #asset_pipeline_gemfile_entry private
- #build(meth, *args) private
- #builder private
- #comment_if(value) private
- #create_root private
- #database_gemfile_entry private
- #deduce_implied_options(options, option_reasons, meta_options) private
- #gemfile_entries private
-
#imply_options(option_implications = OPTION_IMPLICATIONS, meta_options: [])
private
Options.
- #rails_require_statement private
- #report_implied_options private
- #required_railties private
- #set_default_accessors! private
- #web_server_gemfile_entry private
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(positional_argv, option_argv) ⇒ AppBase
# File 'railties/lib/rails/generators/app_base.rb', line 141
def initialize(positional_argv, option_argv, *) @argv = [*positional_argv, *option_argv] @gem_filter = lambda { |gem| true } super end
Class Method Details
.edge_branch
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 137
def self.edge_branch # :nodoc: Rails.gem_version.prerelease? ? "main" : [*Rails.gem_version.segments.first(2), "stable"].join("-") end
.strict_args_position
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 28
def self.strict_args_position false end
Instance Attribute Details
#bundle_install? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 666
def bundle_install? !( [:skip_bundle] || [:pretend]) end
#depend_on_bootsnap? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 674
def depend_on_bootsnap? ! [:skip_bootsnap] && ! [:dev] && !defined?(JRUBY_VERSION) end
#depends_on_system_test? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 670
def depends_on_system_test? !( [:skip_system_test] || [:skip_test] || [:api]) end
#devcontainer? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 408
def devcontainer? [:devcontainer] end
#include_all_railties? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 315
def include_all_railties? # :doc: required_railties.values.all? end
#keeps? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 348
def keeps? # :doc: ! [:skip_keeps] end
#rails_prerelease? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 456
def rails_prerelease? .dev? || .edge? || .main? end
#rails_template (rw)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 23
attr_accessor :rails_template
#skip_action_cable? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 368
def skip_action_cable? # :doc: [:skip_action_cable] end
#skip_action_mailbox? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 376
def skip_action_mailbox? # :doc: [:skip_action_mailbox] end
#skip_action_mailer? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 372
def skip_action_mailer? # :doc: [:skip_action_mailer] end
#skip_action_text? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 380
def skip_action_text? # :doc: [:skip_action_text] end
#skip_active_record? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 356
def skip_active_record? # :doc: [:skip_active_record] end
#skip_active_storage? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 360
def skip_active_storage? # :doc: [:skip_active_storage] end
#skip_asset_pipeline? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 384
def skip_asset_pipeline? # :doc: [:skip_asset_pipeline] end
#skip_brakeman? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 396
def skip_brakeman? [:skip_brakeman] end
#skip_ci? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 400
def skip_ci? [:skip_ci] end
#skip_devcontainer? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 404
def skip_devcontainer? ! [:devcontainer] end
#skip_kamal? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 412
def skip_kamal? [:skip_kamal] end
#skip_rubocop? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 392
def skip_rubocop? [:skip_rubocop] end
#skip_solid? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 416
def skip_solid? [:skip_solid] end
#skip_storage? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 364
def skip_storage? # :doc: skip_active_storage? && !sqlite3? end
#skip_thruster? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 388
def skip_thruster? [:skip_thruster] end
#sqlite3? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 352
def sqlite3? # :doc: !skip_active_record? && [:database] == "sqlite3" end
#using_bun? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 522
def using_bun? using_js_runtime? && %w[bun].include?( [:javascript]) end
#using_js_runtime? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 513
def using_js_runtime? ( [:javascript] && !%w[importmap].include?( [:javascript])) || ( [:css] && !%w[tailwind sass].include?( [:css])) end
#using_node? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'railties/lib/rails/generators/app_base.rb', line 518
def using_node? using_js_runtime? && !%w[bun].include?( [:javascript]) end
Instance Method Details
#add_bundler_platforms
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 750
def add_bundler_platforms if bundle_install? # The vast majority of Rails apps will be deployed on `x86_64-linux`. bundle_command("lock --add-platform=x86_64-linux") # Users that develop on M1 mac may use docker and would need `aarch64-linux` as well. bundle_command("lock --add-platform=aarch64-linux") if RUBY_PLATFORM.start_with?("arm64") end end
#apply_rails_template (private)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 264
def apply_rails_template # :doc: apply rails_template if rails_template rescue Thor::Error, LoadError, Errno::ENOENT => e raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}" end
#asset_pipeline_gemfile_entry (private)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 293
def asset_pipeline_gemfile_entry unless skip_asset_pipeline? GemfileEntry.floats "propshaft", "The modern asset pipeline for Rails [https://github.com/rails/propshaft]" end end
#build(meth, *args) (private)
[ GitHub ]#builder (private)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 162
def builder # :doc: @builder ||= begin builder_class = get_builder_class builder_class.include(ActionMethods) builder_class.new(self) end end
#bundle_command(command, env = {})
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 640
def bundle_command(command, env = {}) say_status :run, "bundle #{command}" # We are going to shell out rather than invoking Bundler::CLI.new(command) # because `rails new` loads the Thor gem and on the other hand bundler uses # its own vendored Thor, which could be a different version. Running both # things in the same process is a recipe for a night with paracetamol. # # Thanks to James Tucker for the Gem tricks involved in this call. _bundle_command = Gem.bin_path("bundler", "bundle") require "bundler" Bundler.with_original_env do exec_bundle_command(_bundle_command, command, env) end end
#cable_gemfile_entry
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 633
def cable_gemfile_entry if ! [:skip_action_cable] && [:skip_solid] comment = "Use Redis adapter to run Action Cable in production" GemfileEntry.new("redis", ">= 4.0.1", comment, {}, true) end end
#ci_packages
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 612
def ci_packages if depends_on_system_test? dockerfile_build_packages << "google-chrome-stable" else dockerfile_build_packages end end
#comment_if(value) (private)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 335
def comment_if(value) # :doc: question = "#{value}?" comment = if respond_to?(question, true) send(question) else [value] end comment ? "# " : "" end
#create_root (private)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 257
def create_root # :doc: valid_const? empty_directory "." FileUtils.cd(destination_root) unless [:pretend] end
#css_gemfile_entry
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 620
def css_gemfile_entry return if [:api] return unless [:css] if !using_js_runtime? && [:css] == "tailwind" GemfileEntry.floats "tailwindcss-rails", "Use Tailwind CSS [https://github.com/rails/tailwindcss-rails]" elsif !using_js_runtime? && [:css] == "sass" GemfileEntry.floats "dartsass-rails", "Use Dart SASS [https://github.com/rails/dartsass-rails]" else GemfileEntry.floats "cssbundling-rails", "Bundle and process CSS [https://github.com/rails/cssbundling-rails]" end end
#database
[ GitHub ]#database_gemfile_entry (private)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 281
def database_gemfile_entry # :doc: return if [:skip_active_record] gem_name, gem_version = database.gem GemfileEntry.version gem_name, gem_version, "Use #{ [:database]} as the database for Active Record" end
#deduce_implied_options(options, option_reasons, meta_options) (private)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 174
def (, option_reasons, ) active = .transform_values { |value| [] if value }.compact irrevocable = (active.keys - ).to_set deduction_order = TSort.tsort( ->(&block) { option_reasons.each_key(&block) }, ->(key, &block) { option_reasons[key]&.each(&block) } ) deduction_order.each do |name| active_reasons = option_reasons[name].to_a.select(&active) active[name] ||= active_reasons if active_reasons.any? irrevocable << name if active_reasons.any?(irrevocable) end revoked = .select { |name, value| value == false }.keys.to_set - irrevocable deduction_order.reverse_each do |name| revoked += option_reasons[name].to_a if revoked.include?(name) end revoked -= active.filter_map do |name, reasons| unless revoked.include?(name) || reasons.all?(revoked) [name, reasons - revoked.to_a] end end.to_h end
#dockerfile_base_packages
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 577
def dockerfile_base_packages # Add curl to work with the default health check strategy in Kamal packages = ["curl"] # ActiveRecord databases packages << database.base_package unless skip_active_record? # ActiveStorage preview support packages << "libvips" unless skip_active_storage? # jemalloc for memory optimization packages << "libjemalloc2" packages.compact.sort end
#dockerfile_binfile_fixups
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 548
def dockerfile_binfile_fixups # binfiles may have OS specific paths to ruby. Normalize them. shebangs = Dir["bin/*"].map { |file| IO.read(file).lines.first }.join rubies = shebangs.scan(%r{#!/usr/bin/env (ruby.*)}).flatten.uniq binfixups = (rubies - %w(ruby)).map do |ruby| "sed -i 's/#{Regexp.quote(ruby)}$/ruby/' bin/*" end # Windows line endings will cause scripts to fail. If any # or found OR this generation is run on a windows platform # and there are other binfixups required, then convert # line endings. This avoids adding unnecessary fixups if # none are required, but prepares for the need to do the # fix line endings if other fixups are required. has_cr = Dir["bin/*"].any? { |file| IO.read(file).include? "\r" } if has_cr || (Gem.win_platform? && !binfixups.empty?) binfixups.unshift 'sed -i "s/\r$//g" bin/*' end # Windows file systems may not have the concept of executable. # In such cases, fix up during the build. unless Dir["bin/*"].all? { |file| File.executable? file } binfixups.unshift "chmod +x bin/*" end binfixups end
#dockerfile_build_packages
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 593
def dockerfile_build_packages # start with the essentials packages = %w(build-essential git pkg-config) # add database support packages << database.build_package unless skip_active_record? packages << "unzip" if using_bun? # node support, including support for building native modules if using_node? packages << "node-gyp" # pkg-config already listed above packages << "python-is-python3" end packages.compact.sort end
#dockerfile_bun_version
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 542
def dockerfile_bun_version using_bun? and `bun --version`[/\d\.\d\.\d+/] rescue BUN_VERSION end
#dockerfile_chown_directories
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 795
def dockerfile_chown_directories directories = %w(log tmp) directories << "storage" unless skip_storage? directories << "db" unless skip_active_record? directories.sort end
#dockerfile_yarn_version
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 536
def dockerfile_yarn_version using_node? and `yarn --version`[/\d\.\d\.\d+/] rescue "latest" end
#edge_branch
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 791
def edge_branch self.class.edge_branch end
#empty_directory_with_keep_file(destination, config = {})
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 766
def empty_directory_with_keep_file(destination, config = {}) empty_directory(destination, config) keep_file(destination) end
#exec_bundle_command(bundle_command, command, env)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 657
def exec_bundle_command(bundle_command, command, env) full_command = %Q["#{Gem.ruby}" "#{bundle_command}" #{command}] if [:quiet] system(env, full_command, out: File::NULL) else system(env, full_command) end end
#gemfile_entries (private)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 148
def gemfile_entries # :doc: [ rails_gemfile_entry, asset_pipeline_gemfile_entry, database_gemfile_entry, web_server_gemfile_entry, javascript_gemfile_entry, hotwire_gemfile_entry, css_gemfile_entry, jbuilder_gemfile_entry, cable_gemfile_entry, ].flatten.compact.select(&@gem_filter) end
#generate_bundler_binstub
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 760
def generate_bundler_binstub if bundle_install? bundle_command("binstubs bundler") end end
#git_init_command
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 779
def git_init_command return "git init" if user_default_branch.strip.present? git_version = `git --version`[/\d\.\d\.\d+/] if Gem::Version.new(git_version) >= Gem::Version.new("2.28.0") "git init -b main" else "git init && git symbolic-ref HEAD refs/heads/main" end end
#hotwire_gemfile_entry
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 501
def hotwire_gemfile_entry return if [:skip_hotwire] turbo_rails_entry = GemfileEntry.floats "turbo-rails", "Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]" stimulus_rails_entry = GemfileEntry.floats "stimulus-rails", "Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]" [ turbo_rails_entry, stimulus_rails_entry ] end
#imply_options(option_implications = OPTION_IMPLICATIONS, meta_options: []) (private)
Options
:meta_options
-
A list of generator options which only serve to trigger other options. These options should have no other effects, and will be treated transparently when revoking other options.
For example: –minimal implies both –skip-active-job and –skip-active-storage. Also, –skip-active-job by itself implies –skip-active-storage. If –skip-active-job is explicitly specified, –no-skip-active-storage should raise an error. But, if only –minimal is specified, –no-skip-active-storage should “undo” the implied –skip-active-job. This can be accomplished by passing
meta_options: [:minimal]
.In contrast, –api is not a meta option because it does other things besides implying options such as –skip-asset-pipeline. (And so –api with –no-skip-asset-pipeline should raise an error.)
# File 'railties/lib/rails/generators/app_base.rb', line 227
def (option_implications = OPTION_IMPLICATIONS, meta_options: []) option_reasons = {} option_implications.each do |reason, implications| implications.each do |implication| (option_reasons[implication.to_s] ||= []) << reason.to_s end end @implied_options = (, option_reasons, .map(&:to_s)) @implied_options_conflicts = @implied_options.keys.select { |name| [name] == false } self. = .merge(@implied_options.transform_values { true }).freeze end
#javascript_gemfile_entry
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 491
def javascript_gemfile_entry return if [:skip_javascript] if [:javascript] == "importmap" GemfileEntry.floats "importmap-rails", "Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]" else GemfileEntry.floats "jsbundling-rails", "Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]" end end
#jbuilder_gemfile_entry
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 486
def jbuilder_gemfile_entry return if [:skip_jbuilder] GemfileEntry.new "jbuilder", nil, "Build JSON APIs with ease [https://github.com/rails/jbuilder]", {}, [:api] end
#keep_file(destination)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 771
def keep_file(destination) create_file("#{destination}/.keep") if keeps? end
#node_version
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 526
def node_version if using_node? ENV.fetch("NODE_VERSION") do `node --version`[/\d\.\d\.\d+/] rescue NODE_LTS_VERSION end end end
#rails_gemfile_entry
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 460
def rails_gemfile_entry if .dev? GemfileEntry.path("rails", Rails::Generators::RAILS_DEV_PATH, "Use local checkout of Rails") elsif .edge? GemfileEntry.github("rails", "rails/rails", edge_branch, "Use specific branch of Rails") elsif .main? GemfileEntry.github("rails", "rails/rails", "main", "Use main development branch of Rails") else GemfileEntry.version("rails", rails_version_specifier, %(Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main")) end end
#rails_require_statement (private)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 319
def rails_require_statement if include_all_railties? %(require "rails/all") else require_statements = required_railties.map do |railtie, required| %(#{"# " if !required}require "#{railtie}") end <<~RUBY.strip require "rails" # Pick the frameworks you want: #{require_statements.join("\n")} RUBY end end
#rails_version_specifier(gem_version = Rails.gem_version)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 473
def rails_version_specifier(gem_version = Rails.gem_version) if gem_version.segments.size == 3 || gem_version.release.segments.size == 3 # ~> 1.2.3 # ~> 1.2.3.pre4 "~> #{gem_version}" else # ~> 1.2.3, >= 1.2.3.4 # ~> 1.2.3, >= 1.2.3.4.pre5 patch = gem_version.segments[0, 3].join(".") ["~> #{patch}", ">= #{gem_version}"] end end
#report_implied_options (private)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 240
def return if @implied_options.blank? say "Based on the specified options, the following options will also be activated:" say "" @implied_options.each do |name, reasons| due_to = reasons.map { |reason| "--#{reason.dasherize}" }.join(", ") say " --#{name.dasherize} [due to #{due_to}]" if @implied_options_conflicts.include?(name) say " ERROR: Conflicts with --no-#{name.dasherize}", :red end end say "" raise "Cannot proceed due to conflicting options" if @implied_options_conflicts.any? end
#required_railties (private)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 299
def required_railties @required_railties ||= { "active_model/railtie" => true, "active_job/railtie" => ! [:skip_active_job], "active_record/railtie" => ! [:skip_active_record], "active_storage/engine" => ! [:skip_active_storage], "action_controller/railtie" => true, "action_mailer/railtie" => ! [:skip_action_mailer], "action_mailbox/engine" => ! [:skip_action_mailbox], "action_text/engine" => ! [:skip_action_text], "action_view/railtie" => true, "action_cable/engine" => ! [:skip_action_cable], "rails/test_unit/railtie" => ! [:skip_test], } end
#run_bundle
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 700
def run_bundle bundle_command("install --quiet", "BUNDLE_IGNORE_MESSAGES" => "1") if bundle_install? end
#run_css
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 719
def run_css return if ! [:css] || !bundle_install? if !using_js_runtime? && [:css] == "tailwind" rails_command "tailwindcss:install" elsif !using_js_runtime? && [:css] == "sass" rails_command "dartsass:install" else rails_command "css:install:#{ [:css]}" end end
#run_hotwire
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 713
def run_hotwire return if [:skip_hotwire] || !bundle_install? rails_command "turbo:install stimulus:install" end
#run_javascript
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 704
def run_javascript return if [:skip_javascript] || !bundle_install? case [:javascript] when "importmap" then rails_command "importmap:install" when "webpack", "bun", "esbuild", "rollup" then rails_command "javascript:install:#{ [:javascript]}" end end
#run_kamal
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 731
def run_kamal return if [:skip_kamal] || !bundle_install? bundle_command "binstubs kamal" bundle_command "exec kamal init" template "kamal-secrets.tt", ".kamal/secrets", force: true template "config/deploy.yml", force: true end
#run_solid
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 741
def run_solid return if skip_solid? || !bundle_install? commands = "solid_cache:install solid_queue:install" commands += " solid_cable:install" unless skip_action_cable? rails_command commands end
#set_default_accessors! (private)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 270
def set_default_accessors! # :doc: self.destination_root = File. (app_path, destination_root) if [:template].is_a?(String) && ! [:template].match?(/^https?:\/\//) interpolated = [:template].gsub(/\$(\w+)|\$\{\g<1>\}|%\g<1>%/) { |m| ENV[$1] || m } self.rails_template = File. (interpolated) else self.rails_template = [:template] end end
#target_rails_prerelease(self_command = "new")
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 678
def target_rails_prerelease(self_command = "new") return unless rails_prerelease? && bundle_install? if !File.exist?(File. ("Gemfile", destination_root)) create_file("Gemfile", <<~GEMFILE) source "https://rubygems.org" #{rails_gemfile_entry} GEMFILE run_bundle @argv.delete_at(@argv.index(app_path)) @argv.unshift(destination_root) require "shellwords" bundle_command("exec rails #{self_command} #{Shellwords.join(@argv)}") exit else remove_file("Gemfile") remove_file("Gemfile.lock") end end
#user_default_branch
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 775
def user_default_branch @user_default_branch ||= `git config init.defaultbranch` end
#web_server_gemfile_entry (private)
[ GitHub ]# File 'railties/lib/rails/generators/app_base.rb', line 289
def web_server_gemfile_entry # :doc: GemfileEntry.new "puma", ">= 5.0", "Use the Puma web server [https://github.com/puma/puma]" end