class Cursed::Cursor
Cursor
is a value object that has all the parameters required to determine how to fetch a page of records using the cursor pattern.
Constants
- DIRECTIONS
Attributes
Public Class Methods
@param [Integer] after The cursor index to retrieve records after @param [Integer] before The cursor index to retrive records before @param [Integer] limit The maximum number of records to retrieve @param [Integer] maximum The maximum value that :limit can have @param [Symbol] attribute The name of the attribute to cursor upon @param [:forward or :backward] direction The direction the cursor will advance in the collection
# File lib/cursed/cursor.rb, line 17 def initialize(after: nil, before: nil, limit: 10, maximum: 20, attribute: :cursor, direction: :forward) @after = Integer(after) unless after.nil? @before = Integer(before) unless before.nil? @limit = Integer(limit) @maximum = Integer(maximum) @attribute = attribute @direction = direction raise ArgumentError, "#{direction} is not a valid direction" unless DIRECTIONS.include?(direction) end
Public Instance Methods
returns true when the after parameter is set to a non-nil value
# File lib/cursed/cursor.rb, line 48 def after? !after.nil? end
returns true when the direction is backward
# File lib/cursed/cursor.rb, line 38 def backward? direction == :backward end
returns true when the before parameter is set to a non-nil value
# File lib/cursed/cursor.rb, line 43 def before? !before.nil? end
returns the value of {#limit} clamped into the range of 1..{#maximum} (inclusive)
# File lib/cursed/cursor.rb, line 28 def clamped_limit [1, limit, maximum].sort[1] end
returns true when the direction is forward
# File lib/cursed/cursor.rb, line 33 def forward? direction == :forward end