Sha256: 403891f023f1d5b3c5a2d6c018f2e8ad348268be70f77758275ac80c36836f0a

Contents?: true

Size: 1.4 KB

Versions: 17

Compression:

Stored size: 1.4 KB

Contents

# :nocov:
module PgEngine
  module TpathSupport
    module RequestsPatch
      def get(url, **)
        super(tpath(url), **)
      end

      def post(url, **)
        super(tpath(url), **)
      end

      def put(url, **)
        super(tpath(url), **)
      end

      def patch(url, **)
        super(tpath(url), **)
      end

      def delete(url, **)
        super(tpath(url), **)
      end

      def redirect_to(arg, tpath: true)
        if tpath
          super(tpath(arg, query_string: false))
        else
          super(arg)
        end
      end
    end

    module ControllersPatch
      def redirect_to(arg, tpath: true)
        if tpath
          super(tpath(arg, query_string: false))
        else
          super(arg)
        end
      end
    end

    def _tpath_ua
      usr = if respond_to?(:logged_user)
              logged_user
            elsif respond_to?(:user)
              user
            else
              raise 'no user available'
            end

      raise 'user is null' if usr.nil?

      usr.active_user_account_for(ActsAsTenant.current_tenant)
    end

    def tpath(arg, query_string: true)
      ua = _tpath_ua
      return arg.push(tid: ua.to_param) if arg.is_a? Array

      path = arg

      if query_string
        "#{path}?tid=#{ua.to_param}"
      else
        # "/u/t/#{ua.to_param}#{path}"
        path.sub('/u/t/', "/u/t/#{ua.to_param}/")
      end
    end
  end
end
# :nocov:

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
pg_rails-7.6.23 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.22 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.22.pre.3 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.22.pre.2 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.22.pre.1 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.21 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.21.pre.11 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.21.pre.10 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.21.pre.9 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.21.pre.8 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.21.pre.7 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.21.pre.6 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.21.pre.5 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.21.pre.4 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.21.pre.3 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.21.pre.2 pg_rails/lib/pg_rails/tpath_support.rb
pg_rails-7.6.21.pre.1 pg_rails/lib/pg_rails/tpath_support.rb