Sha256: 270ea77b987e4181a1bcfbb62de404fb861cb18bd2b927ceaacb04e27f895312

Contents?: true

Size: 872 Bytes

Versions: 4

Compression:

Stored size: 872 Bytes

Contents

# frozen_string_literal: true

module RailsMiniProfiler
  class User
    class << self
      def current_user
        Thread.current[:rails_mini_profiler_current_user]
      end

      def get(env)
        new(Thread.current[:rails_mini_profiler_current_user], env).current_user
      end

      def authorize(user)
        Thread.current[:rails_mini_profiler_current_user] = user
      end

      def current_user=(user)
        Thread.current[:rails_mini_profiler_current_user] = user
      end
    end

    def initialize(current_user, env)
      @current_user = current_user
      @env = env
    end

    def current_user
      @current_user ||= find_current_user
    end

    def find_current_user
      return if Rails.env.production?

      user = RailsMiniProfiler.configuration.user_provider.call(@env)
      User.current_user = user
      user
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails_mini_profiler-0.7.3 lib/rails_mini_profiler/user.rb
rails_mini_profiler-0.7.2 lib/rails_mini_profiler/user.rb
rails_mini_profiler-0.7.1 lib/rails_mini_profiler/user.rb
rails_mini_profiler-0.7.0 lib/rails_mini_profiler/user.rb