module ExceptionHunter::UserAttributesCollector
Utility module used to whitelist the user's attributes. Can be configured in {ExceptionHunter.setup ExceptionHunter.setup
} to extract custom attributes.
@example
ExceptionHunter.setup do |config| config.user_attributes = [:id, :email, :role, :active?] end
Public Instance Methods
collect_attributes(user)
click to toggle source
Gets the attributes configured for the user.
@example
UserAttributesCollector.collect_attributes(current_user) # => { id: 42, email: "example@user.com" }
@param user instance in your application @return [Hash] the whitelisted attributes from the user
# 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
Private Instance Methods
attributes()
click to toggle source
# File lib/exception_hunter/user_attributes_collector.rb, line 32 def attributes Config.user_attributes end