2017-06-22 22:59:18 -04:00
|
|
|
# frozen_string_literal: true
|
2016-08-06 13:15:47 -04:00
|
|
|
require "fileutils"
|
2016-04-11 06:20:53 -04:00
|
|
|
|
2016-03-14 18:02:25 -04:00
|
|
|
module Rails
|
|
|
|
module DevCaching # :nodoc:
|
|
|
|
class << self
|
2016-08-06 13:15:47 -04:00
|
|
|
FILE = "tmp/caching-dev.txt"
|
2016-03-14 18:02:25 -04:00
|
|
|
|
|
|
|
def enable_by_file
|
2016-08-06 13:15:47 -04:00
|
|
|
FileUtils.mkdir_p("tmp")
|
2016-03-14 18:02:25 -04:00
|
|
|
|
|
|
|
if File.exist?(FILE)
|
|
|
|
delete_cache_file
|
2016-08-06 13:15:47 -04:00
|
|
|
puts "Development mode is no longer being cached."
|
2016-03-14 18:02:25 -04:00
|
|
|
else
|
|
|
|
create_cache_file
|
2016-08-06 13:15:47 -04:00
|
|
|
puts "Development mode is now being cached."
|
2016-03-14 18:02:25 -04:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:15:47 -04:00
|
|
|
FileUtils.touch "tmp/restart.txt"
|
|
|
|
FileUtils.rm_f("tmp/pids/server.pid")
|
2016-03-14 18:02:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def enable_by_argument(caching)
|
2016-08-06 13:15:47 -04:00
|
|
|
FileUtils.mkdir_p("tmp")
|
2016-03-14 18:02:25 -04:00
|
|
|
|
|
|
|
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
|