lib/plezi/controller/controller_class.rb in plezi-0.15.1 vs lib/plezi/controller/controller_class.rb in plezi-0.16.0

- old
+ new

@@ -17,11 +17,11 @@ ::Plezi::Base::Router.url_for self, func, params end # @private # This is used internally by Plezi, do not use. - RESERVED_METHODS = [:delete, :create, :update, :new, :show, :pre_connect, :on_open, :on_close, :on_shutdown, :on_message].freeze + RESERVED_METHODS = [:delete, :create, :update, :new, :show, :pre_connect, :on_sse, :on_open, :on_close, :on_shutdown, :on_message].freeze # @private # This function is used internally by Plezi, do not call. def _pl_get_map return @_pl_get_map if @_pl_get_map @@ -71,10 +71,16 @@ @_pl_is_websocket end # @private # This function is used internally by Plezi, do not call. + def _pl_is_sse? + @_pl_is_sse + end + + # @private + # This function is used internally by Plezi, do not call. def _pl_is_ad? @auto_dispatch end # @private @@ -113,13 +119,15 @@ meth_id = _pl_get_map[par_id] return meth_id if par_id && meth_id # puts "matching against #{params}" case params['_method'.freeze] when :get # since this is common, it's pushed upwards. - if env['HTTP_UPGRADE'.freeze] && _pl_is_websocket? && env['HTTP_UPGRADE'.freeze].downcase.start_with?('websocket'.freeze) - @_pl_init_global_data ||= ::Plezi.plezi_initialize # wake up pub/sub drivers in case of `fork` - return :preform_upgrade + if env['rack.upgrade?'.freeze] + if (env['rack.upgrade?'.freeze] == :websocket && _pl_is_websocket?) || (env['rack.upgrade?'.freeze] == :sse && _pl_is_sse?) + @_pl_init_global_data ||= ::Plezi.plezi_initialize # why did we do this? + return :preform_upgrade + end end return :new if _pl_has_new && par_id == 'new'.freeze return meth_id || (_pl_has_show && :show) || nil when :put, :patch return :create if _pl_has_create && (par_id.nil? || par_id == 'new'.freeze) @@ -141,9 +149,10 @@ @_pl_has_new = public_instance_methods(false).include?(:new) @_pl_has_create = public_instance_methods(false).include?(:create) @_pl_has_update = public_instance_methods(false).include?(:update) @_pl_has_delete = public_instance_methods(false).include?(:delete) @_pl_is_websocket = (instance_variable_defined?(:@auto_dispatch) && instance_variable_get(:@auto_dispatch)) || instance_methods(false).include?(:on_message) + @_pl_is_sse = instance_methods(false).include?(:on_sse) _pl_get_map _pl_ad_map _pl_ws_map end end