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


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

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


2
3
4
# File 'app/presenters/user_presenter.rb', line 2

def aspects_ids
  @aspects_ids
end

#userObject

Returns the value of attribute user


2
3
4
# File 'app/presenters/user_presenter.rb', line 2

def user
  @user
end

Instance Method Details

#adminObject


46
47
48
# File 'app/presenters/user_presenter.rb', line 46

def admin
  user.admin?
end

#aspectsObject


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

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

#configured_servicesObject


26
27
28
# File 'app/presenters/user_presenter.rb', line 26

def configured_services
  user.services.map{|service| service.provider }
end

#notifications_countObject


38
39
40
# File 'app/presenters/user_presenter.rb', line 38

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

#servicesObject


22
23
24
# File 'app/presenters/user_presenter.rb', line 22

def services
  ServicePresenter.as_collection(user.services)
end

#to_json(options = {}) ⇒ Object


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

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

#unread_messages_countObject


42
43
44
# File 'app/presenters/user_presenter.rb', line 42

def unread_messages_count
  @unread_message_count ||= user.unread_message_count
end