Skip to content

Commit 9e666d9

Browse files
committed
refactor(pagination): extract page_count calculation into an instance method
1 parent 3db8260 commit 9e666d9

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

lib/jsonapi/paginator.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,18 @@ def self.requires_record_count
131131
true
132132
end
133133

134+
def calculate_page_count(record_count)
135+
(record_count / @size.to_f).ceil
136+
end
137+
134138
def apply(relation, _order_options)
135139
offset = (@number - 1) * @size
136140
relation.offset(offset).limit(@size)
137141
end
138142

139143
def links_page_params(options = {})
140144
record_count = options[:record_count]
141-
page_count = (record_count / @size.to_f).ceil
145+
page_count = calculate_page_count(record_count)
142146

143147
links_page_params = {}
144148

0 commit comments

Comments
 (0)