Class: UserPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/user_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, aspects_ids) ⇒ UserPresenter

Returns a new instance of UserPresenter.


6
7
8
9
# File 'app/presenters/user_presenter.rb', line 6

def initialize(user, aspects_ids)
  self.user        = user
  self.aspects_ids = aspects_ids
end

Instance Attribute Details

#aspects_idsObject

Returns the value of attribute aspects_ids


4
5
6
# File 'app/presenters/user_presenter.rb', line 4

def aspects_ids
  @aspects_ids
end

#userObject

Returns the value of attribute user


4
5
6
# File 'app/presenters/user_presenter.rb', line 4

def user
  @user
end

Instance Method Details

#adminObject


48
49
50
# File 'app/presenters/user_presenter.rb', line 48

def admin
  user.admin?
end

#aspectsObject


32
33
34
35
36
37
38
# File 'app/presenters/user_presenter.rb', line 32

def aspects
  @aspects ||= begin
                 aspects = AspectPresenter.as_collection(user.aspects)
                 no_aspects = aspects_ids.empty?
                 aspects.each {|a| a[:selected] = no_aspects || aspects_ids.include?(a[:id].to_s) }
               end
end

#configured_servicesObject


28
29
30
# File 'app/presenters/user_presenter.rb', line 28

def configured_services
  user.services.map(&:provider)
end

#moderatorObject


52
53
54
# File 'app/presenters/user_presenter.rb', line 52

def moderator
  user.moderator?
end

#notifications_countObject


40
41
42
# File 'app/presenters/user_presenter.rb', line 40

def notifications_count
  @notification_count ||= user.unread_notifications.count
end

#servicesObject


24
25
26
# File 'app/presenters/user_presenter.rb', line 24

def services
  ServicePresenter.as_collection(user.services)
end

#to_json(options = {}) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/presenters/user_presenter.rb', line 11

def to_json(options={})
  user.person.as_api_response(:backbone).update(
    notifications_count:   notifications_count,
    unread_messages_count: unread_messages_count,
    admin:                 admin,
    moderator:             moderator,
    aspects:               aspects,
    services:              services,
    following_count:       user.contacts.receiving.count,
    configured_services:   configured_services
  ).to_json(options)
end

#unread_messages_countObject


44
45
46
# File 'app/presenters/user_presenter.rb', line 44

def unread_messages_count
  @unread_message_count ||= user.unread_message_count
end