Class: RailsSimpleEventSourcing::Paginator
- Inherits:
-
Object
- Object
- RailsSimpleEventSourcing::Paginator
- Defined in:
- lib/rails_simple_event_sourcing/paginator.rb
Instance Attribute Summary collapse
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
Instance Method Summary collapse
-
#initialize(scope:, per_page:, cursor: nil, direction: :next) ⇒ Paginator
constructor
A new instance of Paginator.
- #next? ⇒ Boolean
- #next_cursor ⇒ Object
- #prev? ⇒ Boolean
- #prev_cursor ⇒ Object
- #records ⇒ Object
Constructor Details
#initialize(scope:, per_page:, cursor: nil, direction: :next) ⇒ Paginator
Returns a new instance of Paginator.
7 8 9 10 11 12 |
# File 'lib/rails_simple_event_sourcing/paginator.rb', line 7 def initialize(scope:, per_page:, cursor: nil, direction: :next) @scope = scope @per_page = per_page @cursor = cursor&.to_i @direction = direction end |
Instance Attribute Details
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
5 6 7 |
# File 'lib/rails_simple_event_sourcing/paginator.rb', line 5 def per_page @per_page end |
Instance Method Details
#next? ⇒ Boolean
26 27 28 29 |
# File 'lib/rails_simple_event_sourcing/paginator.rb', line 26 def next? records @has_next end |
#next_cursor ⇒ Object
18 19 20 |
# File 'lib/rails_simple_event_sourcing/paginator.rb', line 18 def next_cursor records.last&.id end |
#prev? ⇒ Boolean
31 32 33 34 |
# File 'lib/rails_simple_event_sourcing/paginator.rb', line 31 def prev? records @has_prev end |
#prev_cursor ⇒ Object
22 23 24 |
# File 'lib/rails_simple_event_sourcing/paginator.rb', line 22 def prev_cursor records.first&.id end |
#records ⇒ Object
14 15 16 |
# File 'lib/rails_simple_event_sourcing/paginator.rb', line 14 def records @records ||= fetch_records end |