Class: Opbeat::ErrorMessage::User

Inherits:
Struct
  • Object
show all
Defined in:
lib/opbeat/error_message/user.rb

Constant Summary collapse

CONTROLLER_KEY =
'action_controller.instance'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Struct

#to_h

Instance Attribute Details

#emailObject

Returns the value of attribute email

Returns:

  • (Object)

    the current value of email



3
4
5
# File 'lib/opbeat/error_message/user.rb', line 3

def email
  @email
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



3
4
5
# File 'lib/opbeat/error_message/user.rb', line 3

def id
  @id
end

#is_authenticatedObject

Returns the value of attribute is_authenticated

Returns:

  • (Object)

    the current value of is_authenticated



3
4
5
# File 'lib/opbeat/error_message/user.rb', line 3

def is_authenticated
  @is_authenticated
end

#usernameObject

Returns the value of attribute username

Returns:

  • (Object)

    the current value of username



3
4
5
# File 'lib/opbeat/error_message/user.rb', line 3

def username
  @username
end

Class Method Details

.from_rack_env(config, env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/opbeat/error_message/user.rb', line 6

def self.from_rack_env config, env
  controller = env[CONTROLLER_KEY]
  method = config.current_user_method.to_sym

  return unless controller && controller.respond_to?(method)

  user = controller.send method

  new(
    true,
    user.respond_to?(:id) ? user.id : nil,
    user.respond_to?(:username) ? user.username : nil,
    user.respond_to?(:email) ? user.email : nil
  )
end