app/controllers/application_controller.rb in local_pac-0.9.0 vs app/controllers/application_controller.rb in local_pac-0.10.0

- old
+ new

@@ -1,19 +1,22 @@ # encoding: utf-8 module LocalPac module App class ApplicationController < Sinatra::Base + set :root, ::File.expand_path('../../', __FILE__) + set :haml, :format => :html5 + enable :protection + enable :session + @local_storage_mutex = Mutex.new + @translation_table_mutex = Mutex.new class << self - attr_reader :local_storage_mutex + attr_reader :local_storage_mutex, :translation_table_mutex end - set :root, ::File.expand_path('../../', __FILE__) - set :haml, :format => :html5 - def local_storage return @local_storage if @local_storage ApplicationController.local_storage_mutex.synchronize do if settings.respond_to? :local_storage @@ -24,10 +27,24 @@ @local_storage = LocalPac::LocalStorage.new end end end + def translation_table + return @translation_table if @translation_table + + ApplicationController.translation_table_mutex.synchronize do + if settings.respond_to? :translation_table + LocalPac.ui_logger.debug 'Using translation table in production mode: loaded once on startup' + @translation_table = settings.translation_table + else + LocalPac.ui_logger.debug 'Using translation table in development mode: reloaded per request' + @translation_table = LocalPac::TranslationTable.new + end + end + end + use Rack::Deflater use Rack::Locale use Rack::NestedParams use Rack::PostBodyContentTypeParser @@ -114,10 +131,11 @@ configure :production do use Rack::CommonLogger, LocalPac::AccessLogger.new(LocalPac.config.access_log) set :raise_errors, false set :local_storage, LocalPac::LocalStorage.new + set :translation_table, LocalPac::TranslationTable.new end configure :development do set :raise_errors, true @@ -126,10 +144,10 @@ end end configure :test do use Rack::CommonLogger, LocalPac::NullAccessLogger.new - set :raise_errors, true + set :raise_errors, false end configure do mime_type :proxy_pac_file, 'application/x-ns-proxy-autoconfig' end