class Cursored::Collection
Attributes
cursor[R]
limit[R]
relation[R]
Public Class Methods
new(relation, opts = {})
click to toggle source
# File lib/cursored/collection.rb, line 3 def initialize(relation, opts = {}) @relation = relation @limit = opts.fetch(:limit, Cursored.config.limit) @cursor = opts[:cursor] end
Public Instance Methods
next()
click to toggle source
# File lib/cursored/collection.rb, line 13 def next records.last.send(Cursored.config.field) if has_more? end
records()
click to toggle source
# File lib/cursored/collection.rb, line 9 def records padded_records[0..(limit - 1)] end
Private Instance Methods
fetch_padded_records()
click to toggle source
# File lib/cursored/collection.rb, line 28 def fetch_padded_records field = Cursored.config.field padded = relation.order(field => :desc).limit(padded_limit) cursor ? padded.where("#{relation.table_name}.#{field} < ?", cursor) : padded end
has_more?()
click to toggle source
# File lib/cursored/collection.rb, line 34 def has_more? padded_records.length == padded_limit end
padded_limit()
click to toggle source
# File lib/cursored/collection.rb, line 20 def padded_limit @padded_limit ||= limit + 1 end
padded_records()
click to toggle source
# File lib/cursored/collection.rb, line 24 def padded_records @padded_records ||= fetch_padded_records end