Class: UserPresenter
- Inherits:
-
Object
- Object
- UserPresenter
- Defined in:
- app/presenters/user_presenter.rb
Instance Attribute Summary collapse
-
#aspects_ids ⇒ Object
Returns the value of attribute aspects_ids.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #admin ⇒ Object
- #aspects ⇒ Object
- #configured_services ⇒ Object
-
#initialize(user, aspects_ids) ⇒ UserPresenter
constructor
A new instance of UserPresenter.
- #notifications_count ⇒ Object
- #services ⇒ Object
- #to_json(options = {}) ⇒ Object
- #unread_messages_count ⇒ Object
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_ids ⇒ Object
Returns the value of attribute aspects_ids
2 3 4 |
# File 'app/presenters/user_presenter.rb', line 2 def aspects_ids @aspects_ids end |
#user ⇒ Object
Returns the value of attribute user
2 3 4 |
# File 'app/presenters/user_presenter.rb', line 2 def user @user end |
Instance Method Details
#admin ⇒ Object
46 47 48 |
# File 'app/presenters/user_presenter.rb', line 46 def admin user.admin? end |
#aspects ⇒ Object
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_services ⇒ Object
26 27 28 |
# File 'app/presenters/user_presenter.rb', line 26 def configured_services user.services.map{|service| service.provider } end |
#notifications_count ⇒ Object
38 39 40 |
# File 'app/presenters/user_presenter.rb', line 38 def notifications_count @notification_count ||= user.unread_notifications.count end |
#services ⇒ Object
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( = {}) self.user.person.as_api_response(:backbone).update( { :notifications_count => notifications_count, :unread_messages_count => , :admin => admin, :aspects => aspects, :services => services, :following_count => self.user.contacts.receiving.count, :configured_services => self.configured_services, } ).to_json() end |
#unread_messages_count ⇒ Object
42 43 44 |
# File 'app/presenters/user_presenter.rb', line 42 def ||= user. end |