Class: PostInteractionPresenter

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

Instance Method Summary collapse

Constructor Details

#initialize(post, current_user) ⇒ PostInteractionPresenter


87
88
89
90
# File 'app/presenters/post_presenter.rb', line 87

def initialize(post, current_user)
  @post = post
  @current_user = current_user
end

Instance Method Details

#as_api(collection) ⇒ Object


101
102
103
104
105
# File 'app/presenters/post_presenter.rb', line 101

def as_api(collection)
  collection.includes(:author => :profile).all.map do |element|
    element.as_api_response(:backbone)
  end
end

#as_json(options = {}) ⇒ Object


92
93
94
95
96
97
98
99
# File 'app/presenters/post_presenter.rb', line 92

def as_json(options={})
  {
      :likes => as_api(@post.likes),
      :reshares => PostPresenter.collection_json(@post.reshares, @current_user),
      :comments => CommentPresenter.as_collection(@post.comments.order('created_at ASC')),
      :participations => as_api(@post.participations)
  }
end