ru.Bee 2.7.17 → 2.7.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8eaf884496bf93cbf6d181a5fa3081dd39c7bef50dd9f7d9b0d03273e7badb01
4
- data.tar.gz: 6732e5abecbde5ba909e126b19654fe5d1c419d7aaf7b4051a8ae3c14dc01eb1
3
+ metadata.gz: c3259d99e11204edf63640fbf913ae79fa59ffda9ea39d50d5b604a5a5920416
4
+ data.tar.gz: 8e0d0139912e774967734197f467661c06eb2a3ab33cdb0381977ede7dab08e3
5
5
  SHA512:
6
- metadata.gz: c9c7802934054261b64d0e5f2c551da238368b6e55c8e5b0f0e4a59a0d3f3b0ab7450e6fe494cce126ba9b5876393e47c8f9ac8787993343b57ce59c328cea51
7
- data.tar.gz: 40e1678a46bf8134ed96fdc26bd58f10eef451fbe4b0459727c7651781202093e226f6182fbd5ac2c5518324b175535f5d4875ff05673152b5cb56eba244a534
6
+ metadata.gz: 1e684ae9168fec0400e252b78e64b74773e8f074879f722b54306fdcae9057e069c20b7276d720476cec635388f774588d31fe73695e3bb87142b03458cec1fb
7
+ data.tar.gz: 72d396aae6e4c299bf6e211b86822c96c17e988c1b066a610914c6d642a59fb20b88ed7445368d19d35c54f9df3c5103b87d1293da378e392e51388499a2cbcb
data/lib/db/test.db CHANGED
Binary file
@@ -50,20 +50,24 @@ module Rubee
50
50
  @__model.owns_many(*args, __query_dataset: @__query_dataset)
51
51
  end
52
52
 
53
- def paginate(*args)
53
+ def paginate(*args, **kwargs)
54
54
  total_count = @__query_dataset.count
55
- current_page, per_page = args
55
+ current_page = kwargs[:page] || args[0]
56
+ per_page = kwargs[:per_page] || args[1]
57
+ total_pages = per_page.to_i > 0 ? (total_count / per_page.to_f).ceil : 1
58
+ current_page = current_page.to_i > 0 ? current_page.to_i : 1
59
+ per_page = per_page.to_i > 0 ? per_page.to_i : 10
56
60
  __pagination_meta = {
57
61
  current_page:,
58
62
  per_page:,
59
63
  total_count:,
60
64
  first_page: current_page == 1,
61
- last_page: current_page == (total_count / per_page.to_f).ceil,
65
+ last_page: current_page == total_pages,
62
66
  prev: current_page > 1 ? current_page - 1 : nil,
63
- next: current_page < (total_count / per_page.to_f).ceil ? current_page + 1 : nil,
67
+ next: current_page < total_pages ? current_page + 1 : nil,
64
68
  }
65
69
 
66
- @__model.paginate(*args, __query_dataset: @__query_dataset, __pagination_meta:)
70
+ @__model.paginate(*args, **kwargs, __query_dataset: @__query_dataset, __pagination_meta:)
67
71
  end
68
72
 
69
73
  def pagination_meta
@@ -264,12 +264,16 @@ module Rubee
264
264
  ::Rubee::AssocArray.new([], self, query_dataset.offset(*args))
265
265
  end
266
266
 
267
- def paginate(page = 1, per_page = 10, options = {})
268
- query_dataset = options[:__query_dataset] || dataset
267
+ def paginate(*args, **kwargs)
268
+ page = kwargs[:page] || args[0]
269
+ per_page = kwargs[:per_page] || args[1]
270
+ query_dataset = kwargs[:__query_dataset] || dataset
271
+ page = page.to_i > 0 ? page.to_i : 1
272
+ per_page = per_page.to_i > 0 ? per_page.to_i : 10
269
273
  offset = (page - 1) * per_page
270
274
 
271
275
  ::Rubee::AssocArray.new([], self, query_dataset.offset(offset).limit(per_page),
272
- pagination_meta: options[:__pagination_meta])
276
+ pagination_meta: kwargs[:__pagination_meta])
273
277
  end
274
278
 
275
279
  def create(attrs)
data/lib/rubee.rb CHANGED
@@ -20,7 +20,7 @@ module Rubee
20
20
  RUBEE_SUPPORT = { "Rubee::Support::Hash" => Hash, "Rubee::Support::String" => String }
21
21
  end
22
22
 
23
- VERSION = '2.7.17'
23
+ VERSION = '2.7.19'
24
24
 
25
25
  require_relative 'rubee/router'
26
26
  require_relative 'rubee/logger'
@@ -116,6 +116,48 @@ describe 'Comment model' do
116
116
  )
117
117
  Comment.destroy_all
118
118
  end
119
+
120
+ describe 'when pass page number as zero' do
121
+ it 'returns target records' do
122
+ Comment.destroy_all cascade: true
123
+ 10.times do |n|
124
+ Comment.new(text: "test_#{n}").save
125
+ end
126
+ comments = Comment.all.paginate(0, 5)
127
+ _(comments.count).must_equal(5)
128
+ _(comments.pagination_meta).must_equal(
129
+ current_page: 1,
130
+ per_page: 5,
131
+ total_count: 10,
132
+ first_page: true,
133
+ last_page: false,
134
+ prev: nil,
135
+ next: 2
136
+ )
137
+ Comment.destroy_all
138
+ end
139
+ end
140
+
141
+ describe 'when pass args as hash' do
142
+ it 'returns target records' do
143
+ Comment.destroy_all cascade: true
144
+ 10.times do |n|
145
+ Comment.new(text: "test_#{n}").save
146
+ end
147
+ comments = Comment.all.paginate(page: 1, per_page: 5)
148
+ _(comments.count).must_equal(5)
149
+ _(comments.pagination_meta).must_equal(
150
+ current_page: 1,
151
+ per_page: 5,
152
+ total_count: 10,
153
+ first_page: true,
154
+ last_page: false,
155
+ prev: nil,
156
+ next: 2
157
+ )
158
+ Comment.destroy_all
159
+ end
160
+ end
119
161
  end
120
162
  end
121
163
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ru.Bee
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.17
4
+ version: 2.7.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Saltykov