Class: Rails::Generators::ARGVScrubber
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | railties/lib/rails/generators/rails/app/app_generator.rb |
Overview
This class handles preparation of the arguments before the AppGenerator
is called. The class provides version or help information if they were requested, and also constructs the railsrc file (used for extra configuration options).
This class should be called before the AppGenerator
is required and started since it configures and mutates ARGV correctly.
Class Method Summary
- .default_rc_file
- .new(argv = ARGV) ⇒ ARGVScrubber constructor
Instance Method Summary
- #prepare!
- #handle_invalid_command!(argument, argv) private
- #handle_rails_rc!(argv) private
- #handle_version_request!(argument) private
- #insert_railsrc_into_argv!(argv, railsrc) private
- #railsrc(argv) private
- #read_rc_file(railsrc) private
Constructor Details
.new(argv = ARGV) ⇒ ARGVScrubber
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 612
def initialize(argv = ARGV) @argv = argv end
Class Method Details
.default_rc_file
[ GitHub ]Instance Method Details
#handle_invalid_command!(argument, argv) (private)
[ GitHub ]# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 642
def handle_invalid_command!(argument, argv) if argument == "new" yield else ["--help"] + argv.drop(1) end end
#handle_rails_rc!(argv) (private)
[ GitHub ]# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 650
def handle_rails_rc!(argv) if argv.find { |arg| arg == "--no-rc" } argv.reject { |arg| arg == "--no-rc" } else railsrc(argv) { |rc_argv, rc| insert_railsrc_into_argv!(rc_argv, rc) } end end
#handle_version_request!(argument) (private)
[ GitHub ]#insert_railsrc_into_argv!(argv, railsrc) (private)
[ GitHub ]# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 673
def insert_railsrc_into_argv!(argv, railsrc) return argv unless File.exist?(railsrc) extra_args = read_rc_file railsrc argv.take(1) + extra_args + argv.drop(1) end
#prepare!
[ GitHub ]# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 616
def prepare! handle_version_request!(@argv.first) handle_invalid_command!(@argv.first, @argv) do handle_rails_rc!(@argv.drop(1)) end end
#railsrc(argv) (private)
[ GitHub ]# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 658
def railsrc(argv) if (customrc = argv.index { |x| x.include?("--rc=") }) fname = File. (argv[customrc].gsub(/--rc=/, "")) yield(argv.take(customrc) + argv.drop(customrc + 1), fname) else yield argv, self.class.default_rc_file end end