Class: Shamu::Entities::PagedList
- Includes:
- Enumerable
- Defined in:
- lib/shamu/entities/paged_list.rb
Overview
A list of Entity records.
Instance Method Summary collapse
-
#current_page ⇒ Integer
The current page number.
-
#first? ⇒ Boolean
set.
-
#initialize(entities, total_count: :not_set, limit: :not_set, offset: :not_set, has_next: :not_set, has_previous: :not_set) ⇒ PagedList
constructor
to a number) of records in the entire set.
-
#last? ⇒ Boolean
set.
-
#limit ⇒ Integer
(also: #per_page)
The maximum number of records to return in each page.
-
#next? ⇒ Boolean
(also: #has_next?)
True if there is another page of data available.
-
#offset ⇒ Integer
data that that this list contains.
-
#paged? ⇒ Boolean
See PagedList for paged implementation.
-
#previous? ⇒ Boolean
(also: #has_prev?, #has_previous)
True if there is another page of data available.
-
#total_count ⇒ Integer
The total number of records in the set.
Methods inherited from List
Constructor Details
#initialize(entities, total_count: :not_set, limit: :not_set, offset: :not_set, has_next: :not_set, has_previous: :not_set) ⇒ PagedList
to a number) of records in the entire set. number) of records in the page represented by the list. number) offset from the start of the set that this list represents. available or a proc that returns a bool. available or a proc that returns a bool.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/shamu/entities/paged_list.rb', line 19 def initialize( entities, total_count: :not_set, limit: :not_set, offset: :not_set, has_next: :not_set, has_previous: :not_set ) super( entities ) @total_count = total_count @limit = limit @offset = offset @has_next = has_next @has_previous = has_previous end |
Instance Method Details
#current_page ⇒ Integer
Returns the current page number.
83 84 85 86 87 88 89 |
# File 'lib/shamu/entities/paged_list.rb', line 83 def current_page if limit > 0 ( offset / limit ).to_i + 1 else 1 end end |
#first? ⇒ Boolean
set.
132 133 134 |
# File 'lib/shamu/entities/paged_list.rb', line 132 def first? !previous? end |
#last? ⇒ Boolean
set.
109 110 111 |
# File 'lib/shamu/entities/paged_list.rb', line 109 def last? !next? end |
#limit ⇒ Integer Also known as: per_page
Returns the maximum number of records to return in each page.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/shamu/entities/paged_list.rb', line 51 def limit if @limit == :not_set if raw_entities.respond_to?( :limit_value ) raw_entities.limit_value elsif raw_entities.respond_to?( :limit ) raw_entities.limit end elsif @limit.respond_to?( :call ) @limit = @limit.call else @limit end end |
#next? ⇒ Boolean Also known as: has_next?
Returns true if there is another page of data available.
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/shamu/entities/paged_list.rb', line 92 def next? if @has_next == :not_set if raw_entities.respond_to?( :has_next? ) raw_entities.has_next? elsif raw_entities.respond_to?( :last_page? ) !raw_entities.last_page? end elsif @has_next.respond_to?( :call ) @has_next = @has_next.call else @has_next end end |
#offset ⇒ Integer
data that that this list contains.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/shamu/entities/paged_list.rb', line 68 def offset if @offset == :not_set if raw_entities.respond_to?( :offset_value ) raw_entities.offset_value elsif raw_entities.respond_to?( :offset ) raw_entities.offset end elsif @offset.respond_to?( :call ) @offset = @offset.call else @offset end end |
#paged? ⇒ Boolean
See Shamu::Entities::PagedList for paged implementation.
35 36 37 |
# File 'lib/shamu/entities/paged_list.rb', line 35 def paged? true end |
#previous? ⇒ Boolean Also known as: has_prev?, has_previous
Returns true if there is another page of data available.
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/shamu/entities/paged_list.rb', line 114 def previous? if @has_previous == :not_set if raw_entities.respond_to?( :has_previous? ) raw_entities.has_previous? elsif raw_entities.respond_to?( :first_page? ) !raw_entities.first_page? end elsif @has_previous.respond_to?( :call ) @has_previous = @has_previous.call else @has_previous end end |
#total_count ⇒ Integer
Returns the total number of records in the set.
40 41 42 43 44 45 46 47 48 |
# File 'lib/shamu/entities/paged_list.rb', line 40 def total_count if @total_count == :not_set raw_entities.total_count elsif @total_count.respond_to?( :call ) @total_count = @total_count.call else @total_count end end |