Class: Sunspot::NullResult::PaginatedNullArray

Inherits:
Array
  • Object
show all
Defined in:
lib/sunspot/null_result/paginated_null_array.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, current_page: 1, per_page: 1, offset: nil) ⇒ PaginatedNullArray

Returns a new instance of PaginatedNullArray.



11
12
13
14
15
16
17
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 11

def initialize(collection, current_page: 1, per_page: 1, offset: nil)
  super(collection)
  @current_page = current_page.to_i
  @per_page     = per_page.to_i
  @offset       = offset
  @_collection  = collection
end

Instance Attribute Details

#per_pageObject (readonly) Also known as: limit_value

Returns the value of attribute per_page.



9
10
11
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 9

def per_page
  @per_page
end

Instance Method Details

#current_pageObject



39
40
41
42
43
44
45
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 39

def current_page
  if @_collection.respond_to?(:current_page)
    @_collection.current_page
  else
    @current_page
  end
end

#first_page?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 55

def first_page?
  true
end

#last_page?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 59

def last_page?
  true
end

#next_pageObject



51
52
53
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 51

def next_page
  (current_page+1) if total_pages > current_page
end

#offsetObject



67
68
69
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 67

def offset
  @offset || 0
end

#out_of_bounds?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 63

def out_of_bounds?
  false
end

#prev_pageObject



47
48
49
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 47

def prev_page
  (current_page-1) if current_page > 1
end

#sizeObject Also known as: total_count



21
22
23
24
25
26
27
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 21

def size
  if @_collection.respond_to?(:total_count)
    @_collection.total_count
  else
    super
  end
end

#total_pagesObject Also known as: num_pages



30
31
32
33
34
35
36
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 30

def total_pages
  if @_collection.respond_to?(:total_pages)
    @_collection.total_pages
  else
    [(size/per_page.to_f).ceil, 1].max
  end
end