Class: InfluxReporter::ErrorMessage::User

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

Constant Summary collapse

CONTROLLER_KEY =
'action_controller.instance'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#emailObject

Returns the value of attribute email

Returns:

  • (Object)

    the current value of email



5
6
7
# File 'lib/influx_reporter/error_message/user.rb', line 5

def email
  @email
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



5
6
7
# File 'lib/influx_reporter/error_message/user.rb', line 5

def id
  @id
end

#is_authenticatedObject

Returns the value of attribute is_authenticated

Returns:

  • (Object)

    the current value of is_authenticated



5
6
7
# File 'lib/influx_reporter/error_message/user.rb', line 5

def is_authenticated
  @is_authenticated
end

#usernameObject

Returns the value of attribute username

Returns:

  • (Object)

    the current value of username



5
6
7
# File 'lib/influx_reporter/error_message/user.rb', line 5

def username
  @username
end

Class Method Details

.from_rack_env(config, env) ⇒ Object



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

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