Class: DynamodbRecord::QueryPager

Inherits:
Pager
  • Object
show all
Defined in:
lib/dynamodb_record/query_pager.rb

Overview

Dynamodb::Page is a class that include logic business from paginate

Instance Attribute Summary collapse

Attributes inherited from Pager

#klass

Instance Method Summary collapse

Constructor Details

#initialize(options, klass) ⇒ QueryPager

Returns a new instance of QueryPager.



8
9
10
11
12
13
# File 'lib/dynamodb_record/query_pager.rb', line 8

def initialize(options, klass)
  super(options, klass)
  response = @klass.client.query(@options)
  @items = response.items
  @last_evaluated_key = response.last_evaluated_key
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



6
7
8
# File 'lib/dynamodb_record/query_pager.rb', line 6

def items
  @items
end

#last_evaluated_keyObject (readonly)

Returns the value of attribute last_evaluated_key.



6
7
8
# File 'lib/dynamodb_record/query_pager.rb', line 6

def last_evaluated_key
  @last_evaluated_key
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/dynamodb_record/query_pager.rb', line 6

def options
  @options
end

Instance Method Details

#next_page(last_key = nil) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/dynamodb_record/query_pager.rb', line 19

def next_page(last_key = nil)
  return nil unless next_page?

  @last_evaluated_key = last_key if last_key.present?

  @options.merge!(exclusive_start_key: last_evaluated_key) if next_page?
  self.class.new(@options, @klass)
end

#next_page?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/dynamodb_record/query_pager.rb', line 15

def next_page?
  last_evaluated_key ? true : false
end