Class: JobBoard::Page
- Inherits:
-
Object
- Object
- JobBoard::Page
- Includes:
- Enumerable
- Defined in:
- app/models/job_board/page.rb
Overview
Keyset pagination over a relation ordered by id DESC. Fetches limit + 1 records to detect whether an older page exists.
Instance Attribute Summary collapse
-
#records ⇒ Object
readonly
Returns the value of attribute records.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(relation, before: nil, limit: 25, &row_builder) ⇒ Page
constructor
A new instance of Page.
- #more? ⇒ Boolean
-
#next_before ⇒ Object
Keyset cursor for the next (older) page — the id of the raw record, which is an execution id for execution-backed lists and a job id for finished.
Constructor Details
#initialize(relation, before: nil, limit: 25, &row_builder) ⇒ Page
Returns a new instance of Page.
9 10 11 12 13 14 15 |
# File 'app/models/job_board/page.rb', line 9 def initialize(relation, before: nil, limit: 25, &row_builder) relation = relation.where(id: ...before.to_i) if before.present? fetched = relation.limit(limit + 1).to_a @more = fetched.size > limit @records = fetched.first(limit) @rows = row_builder ? @records.map(&row_builder) : @records end |
Instance Attribute Details
#records ⇒ Object (readonly)
Returns the value of attribute records.
7 8 9 |
# File 'app/models/job_board/page.rb', line 7 def records @records end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
7 8 9 |
# File 'app/models/job_board/page.rb', line 7 def rows @rows end |
Instance Method Details
#each(&block) ⇒ Object
27 28 29 |
# File 'app/models/job_board/page.rb', line 27 def each(&block) rows.each(&block) end |
#empty? ⇒ Boolean
31 32 33 |
# File 'app/models/job_board/page.rb', line 31 def empty? records.empty? end |
#more? ⇒ Boolean
17 18 19 |
# File 'app/models/job_board/page.rb', line 17 def more? @more end |
#next_before ⇒ Object
Keyset cursor for the next (older) page — the id of the raw record, which is an execution id for execution-backed lists and a job id for finished.
23 24 25 |
# File 'app/models/job_board/page.rb', line 23 def next_before records.last&.id end |