Class: ParamsReady::Pagination::AfterKeysets

Inherits:
AbstractKeysets show all
Defined in:
lib/params_ready/pagination/keysets.rb

Instance Attribute Summary collapse

Attributes inherited from AbstractKeysets

#keysets

Instance Method Summary collapse

Methods inherited from AbstractKeysets

#length, #transform

Constructor Details

#initialize(last, keysets, &block) ⇒ AfterKeysets

Returns a new instance of AfterKeysets.



45
46
47
48
# File 'lib/params_ready/pagination/keysets.rb', line 45

def initialize(last, keysets, &block)
  @last = last
  super keysets, &block
end

Instance Attribute Details

#lastObject (readonly)

Returns the value of attribute last.



43
44
45
# File 'lib/params_ready/pagination/keysets.rb', line 43

def last
  @last
end

Instance Method Details

#page(delta, limit) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/params_ready/pagination/keysets.rb', line 50

def page(delta, limit)
  raise "Expected positive integer for limit, got: #{limit}" if limit < 1
  raise "Expected positive integer for delta, got: #{delta}" if delta < 1
  return if @keysets.length.zero?

  shift = (delta - 1) * limit

  if shift == 0
    @last
  else
    diff = @keysets.length - shift
    if diff < 1
      nil
    else
      transform(@keysets[shift - 1])
    end
  end
end