Class: RailsSimpleEventSourcing::Paginator

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_simple_event_sourcing/paginator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pageObject (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

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/rails_simple_event_sourcing/paginator.rb', line 26

def next?
  records
  @has_next
end

#next_cursorObject



18
19
20
# File 'lib/rails_simple_event_sourcing/paginator.rb', line 18

def next_cursor
  records.last&.id
end

#prev?Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/rails_simple_event_sourcing/paginator.rb', line 31

def prev?
  records
  @has_prev
end

#prev_cursorObject



22
23
24
# File 'lib/rails_simple_event_sourcing/paginator.rb', line 22

def prev_cursor
  records.first&.id
end

#recordsObject



14
15
16
# File 'lib/rails_simple_event_sourcing/paginator.rb', line 14

def records
  @records ||= fetch_records
end