Class: ReshareService

Inherits:
Object
  • Object
show all
Defined in:
app/services/reshare_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(user = nil) ⇒ ReshareService

Returns a new instance of ReshareService.


4
5
6
# File 'app/services/reshare_service.rb', line 4

def initialize(user=nil)
  @user = user
end

Instance Method Details

#create(post_id) ⇒ Object


8
9
10
11
12
# File 'app/services/reshare_service.rb', line 8

def create(post_id)
  post = post_service.find!(post_id)
  post = post.absolute_root if post.is_a? Reshare
  user.reshare!(post)
end

#find_for_post(post_id) ⇒ Object


14
15
16
17
# File 'app/services/reshare_service.rb', line 14

def find_for_post(post_id)
  reshares = post_service.find!(post_id).reshares
  user ? reshares.order(Arel.sql("author_id = #{user.person.id} DESC")) : reshares
end