Class: Enki::CommentActivity
- Inherits:
-
Object
- Object
- Enki::CommentActivity
- Defined in:
- app/models/enki/comment_activity.rb
Instance Attribute Summary collapse
-
#post ⇒ Object
Returns the value of attribute post.
Class Method Summary collapse
Instance Method Summary collapse
- #comments ⇒ Object
-
#initialize(post) ⇒ CommentActivity
constructor
A new instance of CommentActivity.
- #most_recent_comment ⇒ Object
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
#post ⇒ Object
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_recent ⇒ Object
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
#comments ⇒ Object
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_comment ⇒ Object
13 14 15 |
# File 'app/models/enki/comment_activity.rb', line 13 def most_recent_comment comments.first end |