diff options
author | Chuck Callebs <chuck@callebs.io> | 2015-07-20 23:35:20 -0400 |
---|---|---|
committer | Chuck Callebs <chuck@callebs.io> | 2015-08-04 23:41:23 -0400 |
commit | a01e58afd9ef301db17e952a9a42a4ec96cc5661 (patch) | |
tree | e037062e270bf5c88a778b536818b9d568718f1d /railties/lib/rails/commands | |
parent | 10e994cc07dbd4ff87db225f15850197a9c6bb18 (diff) | |
download | rails-a01e58afd9ef301db17e952a9a42a4ec96cc5661.tar.gz rails-a01e58afd9ef301db17e952a9a42a4ec96cc5661.tar.bz2 rails-a01e58afd9ef301db17e952a9a42a4ec96cc5661.zip |
Add rake dev:cache task to enable dev mode caching.
Taken from @Sonopa's commits on PR #19091.
Add support for dev caching via "rails s" flags.
Implement suggestions from @kaspth.
Remove temporary cache file if server does not have flags.
Break at 80 characters in railties/CHANGELOG.md
Remove ability to disable cache based on server options.
Add more comprehensive options: --dev-caching / --no-dev-caching
Diffstat (limited to 'railties/lib/rails/commands')
-rw-r--r-- | railties/lib/rails/commands/server.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index d1e445ac70..8e7f206028 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -34,6 +34,9 @@ module Rails opts.on("-P", "--pid=pid", String, "Specifies the PID file.", "Default: tmp/pids/server.pid") { |v| options[:pid] = v } + opts.on("-C", "--[no-]dev-caching", + "Specifies whether to perform caching in development.", + "true or false") { |v| options[:caching] = v } opts.separator "" @@ -67,6 +70,7 @@ module Rails print_boot_information trap(:INT) { exit } create_tmp_directories + setup_dev_caching log_to_stdout if options[:log_stdout] super @@ -86,12 +90,23 @@ module Rails DoNotReverseLookup: true, environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup, daemonize: false, + caching: false, pid: File.expand_path("tmp/pids/server.pid") }) end private + def setup_dev_caching + return unless options[:environment] == "development" + + if options[:caching] == false + delete_cache_file + elsif options[:caching] + create_cache_file + end + end + def print_boot_information url = "#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}" puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}" @@ -101,6 +116,14 @@ module Rails puts "=> Ctrl-C to shutdown server" unless options[:daemonize] end + def create_cache_file + FileUtils.touch("tmp/caching-dev.txt") + end + + def delete_cache_file + FileUtils.rm("tmp/caching-dev.txt") if File.exists?("tmp/caching-dev.txt") + end + def create_tmp_directories %w(cache pids sockets).each do |dir_to_make| FileUtils.mkdir_p(File.join(Rails.root, 'tmp', dir_to_make)) |