require "fiona7/table_switcher" module Fiona7 module Middleware class TableSwitchingMiddleware def initialize(app) @app = app end def call(env) if Fiona7.mode == :legacy editing_context = env[Scrivito::EditingContextMiddleware::ENVKEY] use_preview = editing_context.authenticated_editor? && selected_workspace_id(editing_context) == 'rtc' (Fiona7::WriteObj.base_class.descendants - [Fiona7::ReleasedObj, Fiona7::InternalReleasedObj, Fiona7::EditedObj] + [Fiona7::WriteObj.base_class]).each do |descendant| TableSwitcher.new( descendant, use_preview ? "preview_objs" : "objs" ).switch end end @app.call(env) end def selected_workspace_id(editing_context) # NOTE: this does not require workspace lookup/load_obj # and thus is potentially faster editing_context.instance_variable_get(:@selected_workspace_id).to_s end end end end