Class: Enki::CommentActivity

Inherits:
Object
  • Object
show all
Defined in:
app/models/enki/comment_activity.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(post) ⇒ CommentActivity

Returns a new instance of CommentActivity.



5
6
7
# File 'app/models/enki/comment_activity.rb', line 5

def initialize(post)
  self.post = post
end

Instance Attribute Details

#postObject

Returns the value of attribute post.



3
4
5
# File 'app/models/enki/comment_activity.rb', line 3

def post
  @post
end

Class Method Details

.find_recentObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/enki/comment_activity.rb', line 18

def find_recent
  Post.find(:all,
    :group  => "comments.post_id, posts." + Post.column_names.join(", posts."),
    :select => 'posts.*, max(comments.created_at), comments.post_id',
    :joins  => 'INNER JOIN comments ON comments.post_id = posts.id',
    :order  => 'max(comments.created_at) desc',
    :limit  => 5
  ).collect {|post|
    CommentActivity.new(post)
  }.sort_by {|activity|
    activity.most_recent_comment.created_at
  }.reverse
end

Instance Method Details

#commentsObject



9
10
11
# File 'app/models/enki/comment_activity.rb', line 9

def comments
  @comments ||= post.approved_comments.find_recent(:limit => 5)
end

#most_recent_commentObject



13
14
15
# File 'app/models/enki/comment_activity.rb', line 13

def most_recent_comment
  comments.first
end