Sha256: d61f6b2e9b5ac5c34e14d49805c8b43f7213dab4ccf9db996933d601d3632652

Contents?: true

Size: 993 Bytes

Versions: 9

Compression:

Stored size: 993 Bytes

Contents

module Bugsnag::Middleware
  class ClearanceUser
    COMMON_USER_FIELDS = [:email, :name, :first_name, :last_name, :created_at, :id]

    def initialize(bugsnag)
      @bugsnag = bugsnag
    end

    def call(notification)
      if notification.request_data[:rack_env] &&
            notification.request_data[:rack_env][:clearance] &&
            notification.request_data[:rack_env][:clearance].signed_in? &&
            notification.request_data[:rack_env][:clearance].current_user

        # Extract useful user information
        user = {}
        user_object = notification.request_data[:rack_env][:clearance].current_user
        if user_object
          # Build the bugsnag user info from the current user record
          COMMON_USER_FIELDS.each do |field|
            user[field] = user_object.send(field) if user_object.respond_to?(field)
          end
        end

        notification.user = user unless user.empty?
      end

      @bugsnag.call(notification)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
bugsnag-5.5.0 lib/bugsnag/middleware/clearance_user.rb
bugsnag-5.4.1 lib/bugsnag/middleware/clearance_user.rb
bugsnag-5.4.0 lib/bugsnag/middleware/clearance_user.rb
bugsnag-5.3.3 lib/bugsnag/middleware/clearance_user.rb
bugsnag-5.3.2 lib/bugsnag/middleware/clearance_user.rb
bugsnag-5.3.1 lib/bugsnag/middleware/clearance_user.rb
bugsnag-5.3.0 lib/bugsnag/middleware/clearance_user.rb
bugsnag-5.2.0 lib/bugsnag/middleware/clearance_user.rb
bugsnag-5.1.0 lib/bugsnag/middleware/clearance_user.rb