module Plezi::Controller::ClassMethods

this module extends the controller class with Plezi functions

Constants

RESERVED_METHODS

@private This is used internally by Plezi, do not use.

Public Class Methods

extended(base) click to toggle source

A Ruby callback used to initialize class data for new Controllers.

# File lib/plezi/controller/controller_class.rb, line 6
def self.extended(base)
   base._pl_init_class_data
end

Public Instance Methods

_pl_ad_map() click to toggle source

@private This function is used internally by Plezi, do not call.

# File lib/plezi/controller/controller_class.rb, line 102
def _pl_ad_map
   return @_pl_ad_map if @_pl_ad_map

   @_pl_ad_map = {}
   mths = public_instance_methods false
   mths.delete_if { |m| m.to_s[0] == '_' || ![-2, -1, 1].freeze.include?(instance_method(m).arity) }
   mths.delete :index
   RESERVED_METHODS.each { |m| mths.delete m }
   mths.each { |m| @_pl_ad_map[m.to_s.freeze] = m; @_pl_ad_map[m] = m }

   @_pl_ad_map
end
_pl_get_map() click to toggle source

@private This function is used internally by Plezi, do not call.

# File lib/plezi/controller/controller_class.rb, line 25
def _pl_get_map
   return @_pl_get_map if @_pl_get_map

   @_pl_get_map = {}
   mths = public_instance_methods false
   mths.delete_if { |mthd| mthd.to_s[0] == '_' || !(-1..0).cover?(instance_method(mthd).arity) }
   @_pl_get_map[nil] = :index if mths.include?(:index)
   RESERVED_METHODS.each { |mthd| mths.delete mthd }
   mths.each { |mthd| @_pl_get_map[mthd.to_s.freeze] = mthd }

   @_pl_get_map
end
_pl_has_create() click to toggle source

@private This function is used internally by Plezi, do not call.

# File lib/plezi/controller/controller_class.rb, line 52
def _pl_has_create
   @_pl_has_create
end
_pl_has_delete() click to toggle source

@private This function is used internally by Plezi, do not call.

# File lib/plezi/controller/controller_class.rb, line 40
def _pl_has_delete
   @_pl_has_delete
end
_pl_has_new() click to toggle source

@private This function is used internally by Plezi, do not call.

# File lib/plezi/controller/controller_class.rb, line 58
def _pl_has_new
   @_pl_has_new
end
_pl_has_show() click to toggle source

@private This function is used internally by Plezi, do not call.

# File lib/plezi/controller/controller_class.rb, line 64
def _pl_has_show
   @_pl_has_show
end
_pl_has_update() click to toggle source

@private This function is used internally by Plezi, do not call.

# File lib/plezi/controller/controller_class.rb, line 46
def _pl_has_update
   @_pl_has_update
end
_pl_init_class_data() click to toggle source

@private This function is used internally by Plezi, do not call.

# File lib/plezi/controller/controller_class.rb, line 145
def _pl_init_class_data
   @auto_dispatch ||= nil
   @_pl_get_map = @_pl_ad_map = @_pl_ws_map = nil
   @_pl_has_show = public_instance_methods(false).include?(:show)
   @_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
_pl_is_ad?() click to toggle source

@private This function is used internally by Plezi, do not call.

# File lib/plezi/controller/controller_class.rb, line 82
def _pl_is_ad?
   @auto_dispatch
end
_pl_is_sse?() click to toggle source

@private This function is used internally by Plezi, do not call.

# File lib/plezi/controller/controller_class.rb, line 76
def _pl_is_sse?
   @_pl_is_sse
end
_pl_is_websocket?() click to toggle source

@private This function is used internally by Plezi, do not call.

# File lib/plezi/controller/controller_class.rb, line 70
def _pl_is_websocket?
   @_pl_is_websocket
end
_pl_params2method(params, env) click to toggle source

@private This function is used internally by Plezi, do not call.

# File lib/plezi/controller/controller_class.rb, line 117
def _pl_params2method(params, env)
   par_id = params['id'.freeze]
   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['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)
      return :update if _pl_has_update
   when :post
      return :create if _pl_has_create
   when :delete
      return :delete if _pl_has_delete
   end
   meth_id || (_pl_has_show && :show) || nil
end
_pl_ws_map() click to toggle source

@private This function is used internally by Plezi, do not call.

# File lib/plezi/controller/controller_class.rb, line 88
def _pl_ws_map
   return @_pl_ws_map if @_pl_ws_map

   @_pl_ws_map = {}
   mths = instance_methods false
   mths.delete :index
   RESERVED_METHODS.each { |mthd| mths.delete mthd }
   mths.each { |mthd| @_pl_ws_map[mthd.to_s.freeze] = mthd; @_pl_ws_map[mthd] = mthd }

   @_pl_ws_map
end
publish(*args) click to toggle source

Publishes a message to a channel.

# File lib/plezi/controller/controller_class.rb, line 11
def publish(*args)
   Iodine.publish *args
end
url_for(func, params = {}) click to toggle source

Returns a relative URL for the controller, placing the requested parameters in the URL (inline, where possible and as query data when not possible).

# File lib/plezi/controller/controller_class.rb, line 16
def url_for(func, params = {})
   ::Plezi::Base::Router.url_for self, func, params
end