Class: Jav::SidebarProfileComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/jav/sidebar_profile_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user:) ⇒ SidebarProfileComponent

Returns a new instance of SidebarProfileComponent.



6
7
8
9
# File 'app/components/jav/sidebar_profile_component.rb', line 6

def initialize(user:)
  super
  @user = user
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'app/components/jav/sidebar_profile_component.rb', line 4

def user
  @user
end

Instance Method Details

#avatarObject



11
12
13
14
15
16
17
# File 'app/components/jav/sidebar_profile_component.rb', line 11

def avatar
  if user.respond_to?(:avatar) && user.avatar.present?
    user.avatar
  else
    ""
  end
end

#can_destroy_user?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/components/jav/sidebar_profile_component.rb', line 43

def can_destroy_user?
  helpers.main_app.respond_to?(destroy_user_session_path)
end

#destroy_user_session_pathObject



37
38
39
40
41
# File 'app/components/jav/sidebar_profile_component.rb', line 37

def destroy_user_session_path
  # If `sign_out_path_name` is configured, use it. Otherwise construct the
  # path name based on `current_user_resource_name`.
  (Jav.configuration.sign_out_path_name || "destroy_#{Jav.configuration.current_user_resource_name}_session_path").to_sym
end

#nameObject



19
20
21
22
23
24
25
26
27
# File 'app/components/jav/sidebar_profile_component.rb', line 19

def name
  if user.respond_to?(:name) && user.name.present?
    user.name
  elsif user.respond_to?(:email) && user.email.present?
    user.email
  else
    "Jav user"
  end
end

#titleObject



29
30
31
32
33
34
35
# File 'app/components/jav/sidebar_profile_component.rb', line 29

def title
  if user.respond_to?(:jav_title) && user.jav_title.present?
    user.jav_title
  else
    ""
  end
end