diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-03-14 23:02:25 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2016-03-15 10:16:51 +0100 |
commit | d54de0808c05c3f7c70dee8ab0111a94c8f90d00 (patch) | |
tree | 624ea3490e2ae86c0694e9373ae014b6e726baee /railties/lib | |
parent | 4fb5a92983bb0b88442b33757bb1e2cdfc49ef00 (diff) | |
download | rails-d54de0808c05c3f7c70dee8ab0111a94c8f90d00.tar.gz rails-d54de0808c05c3f7c70dee8ab0111a94c8f90d00.tar.bz2 rails-d54de0808c05c3f7c70dee8ab0111a94c8f90d00.zip |
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.
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/commands/server.rb | 17 | ||||
-rw-r--r-- | railties/lib/rails/dev_caching.rb | 40 | ||||
-rw-r--r-- | railties/lib/rails/tasks/dev.rake | 14 |
3 files changed, 46 insertions, 25 deletions
diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index d7597a13e1..4e5bf34773 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -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)) diff --git a/railties/lib/rails/dev_caching.rb b/railties/lib/rails/dev_caching.rb new file mode 100644 index 0000000000..4760010851 --- /dev/null +++ b/railties/lib/rails/dev_caching.rb @@ -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 diff --git a/railties/lib/rails/tasks/dev.rake b/railties/lib/rails/tasks/dev.rake index ff2de264ce..d2ceaacc0c 100644 --- a/railties/lib/rails/tasks/dev.rake +++ b/railties/lib/rails/tasks/dev.rake @@ -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 |