Add skip_bootsnap
option
`bootsnap` is a useful gem normally. However, `bootsnap` is unnecessary when generating a Rails application to be used only for testing. So I want to control whether use this or not by option.
This commit is contained in:
parent
28d2968533
commit
838b40da84
@ -84,6 +84,9 @@ def self.add_shared_options_for(name)
|
||||
class_option :skip_system_test, type: :boolean, default: false,
|
||||
desc: "Skip system test files"
|
||||
|
||||
class_option :skip_bootsnap, type: :boolean, default: false,
|
||||
desc: "Skip bootsnap gem"
|
||||
|
||||
class_option :dev, type: :boolean, default: false,
|
||||
desc: "Setup the #{name} with Gemfile pointing to your Rails checkout"
|
||||
|
||||
@ -435,6 +438,10 @@ def depend_on_listen?
|
||||
!options[:skip_listen] && os_supports_listen_out_of_the_box?
|
||||
end
|
||||
|
||||
def depend_on_bootsnap?
|
||||
!options[:skip_bootsnap]
|
||||
end
|
||||
|
||||
def os_supports_listen_out_of_the_box?
|
||||
RbConfig::CONFIG["host_os"] =~ /darwin|linux/
|
||||
end
|
||||
|
@ -29,9 +29,11 @@ ruby <%= "'#{RUBY_VERSION}'" -%>
|
||||
# Use Capistrano for deployment
|
||||
# gem 'capistrano-rails', group: :development
|
||||
|
||||
<% if depend_on_bootsnap? -%>
|
||||
# Reduces boot times through caching; required in config/boot.rb
|
||||
gem 'bootsnap', '>= 1.1.0', require: false
|
||||
|
||||
<%- end -%>
|
||||
<%- if options.api? -%>
|
||||
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
|
||||
# gem 'rack-cors'
|
||||
|
@ -1,7 +1,9 @@
|
||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
||||
|
||||
require 'bundler/setup' # Set up gems listed in the Gemfile.
|
||||
<% if depend_on_bootsnap? -%>
|
||||
require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
|
||||
<%- end -%>
|
||||
|
||||
if %w[s server c console].any? { |a| ARGV.include?(a) }
|
||||
puts "=> Booting Rails"
|
||||
|
@ -792,6 +792,26 @@ def test_generator_if_skip_turbolinks_is_given
|
||||
end
|
||||
end
|
||||
|
||||
def test_bootsnap
|
||||
run_generator
|
||||
|
||||
assert_gem "bootsnap"
|
||||
assert_file "config/boot.rb" do |content|
|
||||
assert_match(/require 'bootsnap\/setup'/, content)
|
||||
end
|
||||
end
|
||||
|
||||
def test_skip_bootsnap
|
||||
run_generator [destination_root, "--skip-bootsnap"]
|
||||
|
||||
assert_file "Gemfile" do |content|
|
||||
assert_no_match(/bootsnap/, content)
|
||||
end
|
||||
assert_file "config/boot.rb" do |content|
|
||||
assert_no_match(/require 'bootsnap\/setup'/, content)
|
||||
end
|
||||
end
|
||||
|
||||
def test_inclusion_of_ruby_version
|
||||
run_generator
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user