major refactoring of post sets and pagination, incomplete
This commit is contained in:
29
app/logical/post_sets/sequential.rb
Normal file
29
app/logical/post_sets/sequential.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
module PostSets
|
||||
module Sequential
|
||||
attr_reader :before_id, :after_id
|
||||
|
||||
def initialize(params)
|
||||
super
|
||||
@before_id = params[:before_id]
|
||||
@after_id = params[:after_id]
|
||||
end
|
||||
|
||||
def slice(relation)
|
||||
if before_id
|
||||
relation.where("id < ?", before_id).all
|
||||
elsif after_id
|
||||
relation.where("id > ?", after_id).order("id asc").all.reverse
|
||||
else
|
||||
relation.all
|
||||
end
|
||||
end
|
||||
|
||||
def pagination_options
|
||||
{:before_id => before_id, :after_id => after_id}
|
||||
end
|
||||
|
||||
def is_first_page?
|
||||
before_id.nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user