Class: Libertree::Model::CommentLike

Inherits:
Object
  • Object
show all
Defined in:
lib/libertree/model/comment-like.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(*args) ⇒ Object



53
54
55
56
57
# File 'lib/libertree/model/comment-like.rb', line 53

def self.create(*args)
  like = super
  like.comment.notify_about_like like
  like
end

Instance Method Details

#after_createObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/libertree/model/comment-like.rb', line 4

def after_create
  super
  if self.local? && self.comment.post.distribute?
    Libertree::Model::Job.create_for_forests(
      {
        task: 'request:COMMENT-LIKE',
        params: { 'comment_like_id' => self.id, }
      },
      *self.forests
    )
  end
end

#before_destroyObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/libertree/model/comment-like.rb', line 29

def before_destroy
  if self.local? && self.comment.post.distribute?
    Libertree::Model::Job.create_for_forests(
      {
        task: 'request:COMMENT-LIKE-DELETE',
        params: { 'comment_like_id' => self.id, }
      },
      *self.forests
    )
  end
  super
end

#commentObject



25
26
27
# File 'lib/libertree/model/comment-like.rb', line 25

def comment
  @comment ||= Comment[self.comment_id]
end

#deleteObject

TODO: the correct method to call is “destroy”



43
44
45
46
# File 'lib/libertree/model/comment-like.rb', line 43

def delete
  self.before_destroy
  super
end

#delete_cascadeObject



48
49
50
51
# File 'lib/libertree/model/comment-like.rb', line 48

def delete_cascade
  self.before_destroy
  DB.dbh[ "SELECT delete_cascade_comment_like(?)", self.id ].get
end

#forestsObject



59
60
61
62
63
64
65
# File 'lib/libertree/model/comment-like.rb', line 59

def forests
  if self.comment.post.remote?
    self.comment.post.server.forests
  else
    Libertree::Model::Forest.all_local_is_member
  end
end

#local?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/libertree/model/comment-like.rb', line 17

def local?
  self.remote_id.nil?
end

#memberObject



21
22
23
# File 'lib/libertree/model/comment-like.rb', line 21

def member
  @member ||= Member[self.member_id]
end