pagy 4.8.1 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c87ea4c3c1bf0dbfb6ae76db111177cda391165a844ff3302f8ee2722249ef2f
4
- data.tar.gz: 26618714b6555f46cb9c140166b3407efb350bf8263cfcb8bdd4bde293265ca9
3
+ metadata.gz: e74b8c735813ad07410c45184e0f8ff345ba104ff3f0bdd75a763a137a63aa53
4
+ data.tar.gz: b9fc3f608fadcc6be76c1374bded0963a0b45b322321001d8b371148e537e4cd
5
5
  SHA512:
6
- metadata.gz: 5e0026cc9cb9051f43c3b89a3d68bde3fbb738ea21055117da0427e0dba9eae6c1d501dcd76d5dadd68890609fde321d33372fe8c949cf8c03c3388e4aa61317
7
- data.tar.gz: 643f315b5de922a30f47f70465e7e13d7a5837835b6da90cf52cdf491eaec75f66450678094a3cbef0f38d65afd280ddafec0e0dc16dc52a479e324b896655dd
6
+ metadata.gz: d68129e5f7134cfde1dff25ab00350bf6458f3270e64f154fd621a7cdad946628d3ff1a6dc4af267aab9605162ba1e725ed902fa62a74adc6e2ced3348ed8497
7
+ data.tar.gz: 33f1f3fba27c3c4e78cfd52649f82aa430e5d5236eb8cf3e9e300a3dc45b8ada546a1a535ceaf4ae65e9f8693ae61d15dad94582a10bdc9643b8d9e3fc76da85
data/lib/config/pagy.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Pagy initializer file (4.8.1)
3
+ # Pagy initializer file (4.9.0)
4
4
  # Customize only what you really need and notice that Pagy works also without any of the following lines.
5
5
  # Should you just cherry pick part of this file, please maintain the require-order of the extras
6
6
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  function Pagy(){}
4
4
 
5
- Pagy.version = '4.8.1'
5
+ Pagy.version = '4.9.0'
6
6
 
7
7
  Pagy.delay = 100
8
8
 
data/lib/pagy.rb CHANGED
@@ -5,7 +5,7 @@ require 'pathname'
5
5
 
6
6
  # main class
7
7
  class Pagy
8
- VERSION = '4.8.1'
8
+ VERSION = '4.9.0'
9
9
 
10
10
  # Root pathname to get the path of Pagy files like templates or dictionaries
11
11
  def self.root
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pagy
4
+
5
+ VARS[:meilisearch_search_method] ||= :pagy_search
6
+
7
+ module Meilisearch
8
+ # returns an array used to delay the call of #search
9
+ # after the pagination variables are merged to the options
10
+ def pagy_meilisearch(term = nil, **vars)
11
+ [self, term, vars]
12
+ end
13
+ alias_method VARS[:meilisearch_search_method], :pagy_meilisearch
14
+ end
15
+
16
+ # create a Pagy object from a Meilisearch results
17
+ def self.new_from_meilisearch(results, vars={})
18
+ vars[:items] = results.raw_answer[:limit]
19
+ vars[:page] = [results.raw_answer[:offset] / vars[:items], 1].max
20
+ vars[:count] = results.raw_answer[:nbHits]
21
+ new(vars)
22
+ end
23
+
24
+ # Add specialized backend methods to paginate Meilisearch results
25
+ module Backend
26
+ private
27
+
28
+ # Return Pagy object and results
29
+ def pagy_meilisearch(pagy_search_args, vars = {})
30
+ model, term, options = pagy_search_args
31
+ vars = pagy_meilisearch_get_vars(nil, vars)
32
+ options[:limit] = vars[:items]
33
+ options[:offset] = (vars[:page] - 1) * vars[:items]
34
+ results = model.search(term, **options)
35
+ vars[:count] = results.raw_answer[:nbHits]
36
+
37
+ pagy = Pagy.new(vars)
38
+ # with :last_page overflow we need to re-run the method in order to get the hits
39
+ return pagy_meilisearch(pagy_search_args, vars.merge(page: pagy.page)) \
40
+ if defined?(Pagy::UseOverflowExtra) && pagy.overflow? && pagy.vars[:overflow] == :last_page
41
+
42
+ [ pagy, results ]
43
+ end
44
+
45
+ # Sub-method called only by #pagy_meilisearch: here for easy customization of variables by overriding
46
+ # the _collection argument is not available when the method is called
47
+ def pagy_meilisearch_get_vars(_collection, vars)
48
+ pagy_set_items_from_params(vars) if defined?(UseItemsExtra)
49
+ vars[:items] ||= VARS[:items]
50
+ vars[:page] ||= (params[ vars[:page_param] || VARS[:page_param] ] || 1).to_i
51
+ vars
52
+ end
53
+
54
+ end
55
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagy
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.8.1
4
+ version: 4.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Domizio Demichelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-14 00:00:00.000000000 Z
11
+ date: 2021-06-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Agnostic pagination in plain ruby: it works with any framework, ORM
14
14
  and DB type, with all kinds of collections, even pre-paginated, scopes, Arrays,
@@ -72,6 +72,7 @@ files:
72
72
  - lib/pagy/extras/i18n.rb
73
73
  - lib/pagy/extras/items.rb
74
74
  - lib/pagy/extras/materialize.rb
75
+ - lib/pagy/extras/meilisearch.rb
75
76
  - lib/pagy/extras/metadata.rb
76
77
  - lib/pagy/extras/navs.rb
77
78
  - lib/pagy/extras/overflow.rb