Sha256: 6c509a938574d09298ddd46d8f0c35dd964c9fdd9b9c9cd44a645c0da42ba57d

Contents?: true

Size: 1010 Bytes

Versions: 3

Compression:

Stored size: 1010 Bytes

Contents

module Airbrake
  module CurrentUser

    # Returns filtered attributes for current user
    def self.filtered_attributes(controller)
      return {} unless controller.respond_to?(:current_user, true)
      begin
        user = controller.send(:current_user)
      rescue
        # If something goes wrong (perhaps while running rake airbrake:test),
        # use the first User.
        user = User.first
      end
      # Return empty hash if there are no users.
      return {} unless user && user.respond_to?(:attributes)

      # Removes auth-related fields
      attributes = user.attributes.reject do |k, v|
        /password|token|login|sign_in|per_page|_at$/ =~ k
      end
      # Try to include a URL for the user, if possible.
      if url_method = [:user_url, :admin_user_url].detect {|m| controller.respond_to?(m) }
        attributes[:url] = controller.send(url_method, user)
      end
      # Return all keys with non-blank values
      attributes.select {|k,v| v.present? }
    end

  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
airbrake_user_attributes_rails5-0.2.0 lib/airbrake/current_user.rb
airbrake_user_attributes-0.1.6 lib/airbrake/current_user.rb
airbrake_user_attributes-0.1.5 lib/airbrake/current_user.rb