Sha256: 71971dbb1add3b5d4e919329e267c7176fe6eb2682fcc936feaf1ef9a7a62ab7
Contents?: true
Size: 1.64 KB
Versions: 17
Compression:
Stored size: 1.64 KB
Contents
module Raygun class AffectedUser DEFAULT_MAPPING = { identifier: [ :id, :username ], email: :email, full_name: [ :full_name, :name ], first_name: :first_name, uuid: :uuid }.freeze SUPPORTED_ATTRIBUTES = DEFAULT_MAPPING.keys.freeze NAME_TO_RAYGUN_NAME_MAPPING = { identifier: :identifier, email: :email, full_name: :fullName, first_name: :firstName, uuid: :uuid }.freeze class << self def information_hash(user_object) if user_object.nil? || user_object.is_a?(String) handle_anonymous_user(user_object) else handle_known_user(user_object) end end private def handle_anonymous_user(user_object) result = { isAnonymous: true } result[:identifier] = user_object unless user_object.nil? result end def handle_known_user(user_object) SUPPORTED_ATTRIBUTES.reduce({ isAnonymous: false }) do |result, attribute| mapping = Raygun.configuration.affected_user_mapping method = mapping[attribute] value = if method.is_a? Proc method.call(user_object) else attributes = Array(method) attribute_to_use = attributes.select do |attr| user_object.respond_to?(attr, true) end.first user_object.send(attribute_to_use) unless attribute_to_use == nil end result[NAME_TO_RAYGUN_NAME_MAPPING[attribute]] = value unless value == nil result end end end end end
Version data entries
17 entries across 17 versions & 1 rubygems