mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Share dev caching implementation between task and server.
Lets have the server and the Rake task go through the same ropes, so we can share all the file lookup, adding, and deleting code.
This commit is contained in:
parent
4fb5a92983
commit
d54de0808c
3 changed files with 46 additions and 25 deletions
|
@ -2,6 +2,7 @@ require 'fileutils'
|
|||
require 'optparse'
|
||||
require 'action_dispatch'
|
||||
require 'rails'
|
||||
require 'rails/dev_caching'
|
||||
|
||||
module Rails
|
||||
class Server < ::Rack::Server
|
||||
|
@ -100,12 +101,8 @@ module Rails
|
|||
private
|
||||
|
||||
def setup_dev_caching
|
||||
return unless options[:environment] == "development"
|
||||
|
||||
if options[:caching] == false
|
||||
delete_cache_file
|
||||
elsif options[:caching]
|
||||
create_cache_file
|
||||
if options[:environment] == "development"
|
||||
Rails::DevCaching.enable_by_argument(options[:caching])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -116,14 +113,6 @@ module Rails
|
|||
puts "=> Run `rails server -h` for more startup options"
|
||||
end
|
||||
|
||||
def create_cache_file
|
||||
FileUtils.touch("tmp/caching-dev.txt")
|
||||
end
|
||||
|
||||
def delete_cache_file
|
||||
FileUtils.rm("tmp/caching-dev.txt") if File.exist?("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))
|
||||
|
|
40
railties/lib/rails/dev_caching.rb
Normal file
40
railties/lib/rails/dev_caching.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
module Rails
|
||||
module DevCaching # :nodoc:
|
||||
class << self
|
||||
FILE = 'tmp/caching-dev.txt'
|
||||
|
||||
def enable_by_file
|
||||
FileUtils.mkdir_p('tmp')
|
||||
|
||||
if File.exist?(FILE)
|
||||
delete_cache_file
|
||||
puts 'Development mode is no longer being cached.'
|
||||
else
|
||||
create_cache_file
|
||||
puts 'Development mode is now being cached.'
|
||||
end
|
||||
|
||||
FileUtils.touch 'tmp/restart.txt'
|
||||
end
|
||||
|
||||
def enable_by_argument(caching)
|
||||
FileUtils.mkdir_p('tmp')
|
||||
|
||||
if caching
|
||||
create_cache_file
|
||||
elsif caching == false && File.exist?(FILE)
|
||||
delete_cache_file
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def create_cache_file
|
||||
FileUtils.touch FILE
|
||||
end
|
||||
|
||||
def delete_cache_file
|
||||
File.delete FILE
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,16 +1,8 @@
|
|||
require 'rails/dev_caching'
|
||||
|
||||
namespace :dev do
|
||||
desc 'Toggle development mode caching on/off'
|
||||
task :cache do
|
||||
FileUtils.mkdir_p('tmp')
|
||||
|
||||
if File.exist? 'tmp/caching-dev.txt'
|
||||
File.delete 'tmp/caching-dev.txt'
|
||||
puts 'Development mode is no longer being cached.'
|
||||
else
|
||||
FileUtils.touch 'tmp/caching-dev.txt'
|
||||
puts 'Development mode is now being cached.'
|
||||
end
|
||||
|
||||
FileUtils.touch 'tmp/restart.txt'
|
||||
Rails::DevCaching.enable_by_file
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue