Class: Ditty::Services::PaginationWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/ditty/services/pagination_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list) ⇒ PaginationWrapper

Returns a new instance of PaginationWrapper.



8
9
10
# File 'lib/ditty/services/pagination_wrapper.rb', line 8

def initialize(list)
  @list = list
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



60
61
62
63
64
# File 'lib/ditty/services/pagination_wrapper.rb', line 60

def method_missing(method, *args)
  return super unless respond_to_missing?(method)

  list.send(method, *args)
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



6
7
8
# File 'lib/ditty/services/pagination_wrapper.rb', line 6

def list
  @list
end

Instance Method Details

#current_page_record_rangeObject



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ditty/services/pagination_wrapper.rb', line 70

def current_page_record_range
  if list.respond_to? :current_page_record_range
    list.current_page_record_range
  else
    return (0..0) if list.current_page > page_count

    a = 1 + (list.current_page - 1) * page_size
    b = a + page_size - 1
    b = pagination_record_count if b > pagination_record_count
    a..b
  end
end

#first_page?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
# File 'lib/ditty/services/pagination_wrapper.rb', line 20

def first_page?
  if list.respond_to? :'first_page?'
    list.first_page?
  else
    list.current_page == 0
  end
end

#last_page?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
# File 'lib/ditty/services/pagination_wrapper.rb', line 12

def last_page?
  if list.respond_to? :'last_page?'
    list.last_page?
  else
    list.current_page == list.total_pages
  end
end

#page_countObject



36
37
38
39
40
41
42
# File 'lib/ditty/services/pagination_wrapper.rb', line 36

def page_count
  if list.respond_to? :page_count
    list.page_count
  else
    list.total_pages
  end
end

#page_sizeObject



44
45
46
47
48
49
50
# File 'lib/ditty/services/pagination_wrapper.rb', line 44

def page_size
  if list.respond_to? :page_size
    list.page_size
  else
    list.per_page
  end
end

#pagination_record_countObject



52
53
54
55
56
57
58
# File 'lib/ditty/services/pagination_wrapper.rb', line 52

def pagination_record_count
  if list.respond_to? :pagination_record_count
    list.pagination_record_count
  else
    list.total_entries
  end
end

#prev_pageObject



28
29
30
31
32
33
34
# File 'lib/ditty/services/pagination_wrapper.rb', line 28

def prev_page
  if list.respond_to? :prev_page
    list.prev_page
  else
    list.previous_page
  end
end

#respond_to_missing?(method, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/ditty/services/pagination_wrapper.rb', line 66

def respond_to_missing?(method, _include_private = false)
  list.respond_to? method
end