pool views
This commit is contained in:
33
app/logical/post_sets/pool.rb
Normal file
33
app/logical/post_sets/pool.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
module PostSets
|
||||
class Pool < Base
|
||||
attr_reader :pool
|
||||
|
||||
def initialize(pool, options = {})
|
||||
@pool = pool
|
||||
@count = pool.post_id_array.size
|
||||
super(options)
|
||||
end
|
||||
|
||||
def tags
|
||||
"pool:#{pool.name}"
|
||||
end
|
||||
|
||||
def load_posts
|
||||
@posts = pool.posts(:limit => limit, :offset => offset)
|
||||
end
|
||||
|
||||
def sorted_posts
|
||||
sort_posts(@posts)
|
||||
end
|
||||
|
||||
private
|
||||
def sort_posts(posts)
|
||||
posts_by_id = posts.inject({}) do |hash, post|
|
||||
hash[post.id] = post
|
||||
hash
|
||||
end
|
||||
|
||||
@pool.post_id_array.map {|x| posts_by_id[x]}
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user