Class: PersonPresenter

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

Instance Method Summary collapse

Constructor Details

#initialize(person, current_user = nil) ⇒ PersonPresenter


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

def initialize(person, current_user = nil)
  @person = person
  @current_user = current_user
end

Instance Method Details

#as_json(options = {}) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/presenters/person_presenter.rb', line 7

def as_json(options={})
  attrs = @person.as_api_response(:backbone).merge(
      {
          :is_own_profile => is_own_profile
      })

  if is_own_profile || person_is_following_current_user
    attrs.merge!({
                    :location => @person.location,
                    :birthday => @person.formatted_birthday,
                    :bio => @person.bio
                })
  end

  attrs
end

#is_own_profileObject


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

def is_own_profile
  @current_user.try(:person) == @person
end