Module: ExceptionHunter::UserAttributesCollector

Extended by:
UserAttributesCollector
Included in:
UserAttributesCollector
Defined in:
lib/exception_hunter/user_attributes_collector.rb

Overview

Utility module used to whitelist the user's attributes. Can be configured in ExceptionHunter.setup to extract custom attributes.

Examples:

ExceptionHunter.setup do |config|
  config.user_attributes = [:id, :email, :role, :active?]
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.collect_attributes(user) ⇒ Hash

Gets the attributes configured for the user.

Examples:

UserAttributesCollector.collect_attributes(current_user)
# => { id: 42, email: "example@user.com" }

Parameters:

  • user

    instance in your application

Returns:

  • (Hash)

    the whitelisted attributes from the user



22
23
24
25
26
27
28
# File 'lib/exception_hunter/user_attributes_collector.rb', line 22

def collect_attributes(user)
  return {} unless user

  attributes.reduce({}) do |data, attribute|
    data.merge(attribute => user.try(attribute))
  end
end

Instance Method Details

#collect_attributes(user) ⇒ Hash

Gets the attributes configured for the user.

Examples:

UserAttributesCollector.collect_attributes(current_user)
# => { id: 42, email: "example@user.com" }

Parameters:

  • user

    instance in your application

Returns:

  • (Hash)

    the whitelisted attributes from the user



22
23
24
25
26
27
28
# File 'lib/exception_hunter/user_attributes_collector.rb', line 22

def collect_attributes(user)
  return {} unless user

  attributes.reduce({}) do |data, attribute|
    data.merge(attribute => user.try(attribute))
  end
end