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' TableSwitcher.new( Fiona7::WriteObj.base_class, use_preview ? "preview_objs" : "objs" ).switch 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