esse-pagy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (9) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +26 -0
  3. data/CHANGELOG.md +12 -0
  4. data/Gemfile +16 -0
  5. data/Gemfile.lock +135 -0
  6. data/LICENSE +21 -0
  7. data/README.md +45 -0
  8. data/lib/esse/pagy.rb +78 -0
  9. metadata +165 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7ceea73edcb4eacd00a9864b43900232835379755d219c46c4754eda8c776f51
4
+ data.tar.gz: 4d521b34747076bb87b9ca2eb997f09d1138f230c9eb6b1ebb006699c533d72e
5
+ SHA512:
6
+ metadata.gz: 8039872c6747a680ae3c133cb084add0d0035cc8aabeacc69d5a5508c2f3423c3a8b2c0c4e6b51c9a0a6565a78ade5a2c968c52508f4f6b1f1fe8b1e78d4670e
7
+ data.tar.gz: 25c887ea1f45cb9675faa2d96c22b243ff1c7648ae897a5a5a9b52e3832ddac5927b9fed06c5bd01cc845987b665ae9521ffbdbb6f6d014e2ac110d3582ee5ff
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ inherit_mode:
2
+ merge:
3
+ - Exclude
4
+
5
+ require:
6
+ - rubocop-performance
7
+ - rubocop-rspec
8
+ - standard/cop/block_single_line_braces
9
+
10
+ inherit_gem:
11
+ standard: config/base.yml
12
+
13
+ AllCops:
14
+ TargetRubyVersion: 2.5
15
+ SuggestExtensions: false
16
+ Exclude:
17
+ - "db/**/*"
18
+ - "tmp/**/*"
19
+ - "vendor/**/*"
20
+ NewCops: enable
21
+
22
+ RSpec/MultipleExpectations:
23
+ Enabled: false
24
+
25
+ RSpec/ExampleLength:
26
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## 0.0.1 - 2023-11-14
8
+ The first release of the esse-pagy plugin. This release includes the following features:
9
+ * Add `pagy_search` method to the `Esse::Index` class.
10
+ * Add `pagy_search` method to the `Esse::Cluster` class.
11
+ * Add `pagy_esse` method to the `Pagy` class.
12
+ * Add `pagy_esse` method to the `Pagy::Backend` class.
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "pagy", "~> 5.10", ">= 5.10.1"
6
+ gem "esse", "~> 0.2.4"
7
+ gem "esse-rspec", "~> 0.0.1"
8
+
9
+ group :test do
10
+ gem "activesupport"
11
+ gem "rack"
12
+ gem "rake-manifest"
13
+ end
14
+
15
+ # Specify your gem's dependencies in esse-active_record.gemspec
16
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,135 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ esse-pagy (0.0.1)
5
+ esse (>= 0.2.4)
6
+ pagy (>= 5)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (7.1.2)
12
+ base64
13
+ bigdecimal
14
+ concurrent-ruby (~> 1.0, >= 1.0.2)
15
+ connection_pool (>= 2.2.5)
16
+ drb
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ mutex_m
20
+ tzinfo (~> 2.0)
21
+ ast (2.4.2)
22
+ base64 (0.2.0)
23
+ bigdecimal (3.1.4)
24
+ coderay (1.1.3)
25
+ concurrent-ruby (1.2.2)
26
+ connection_pool (2.4.1)
27
+ diff-lcs (1.5.0)
28
+ drb (2.2.0)
29
+ ruby2_keywords
30
+ esse (0.2.4)
31
+ multi_json
32
+ thor (>= 0.19)
33
+ esse-rspec (0.0.1)
34
+ esse (>= 0.2.4)
35
+ rspec (~> 3.12)
36
+ i18n (1.14.1)
37
+ concurrent-ruby (~> 1.0)
38
+ json (2.6.3)
39
+ language_server-protocol (3.17.0.3)
40
+ lint_roller (1.1.0)
41
+ method_source (1.0.0)
42
+ minitest (5.20.0)
43
+ multi_json (1.15.0)
44
+ mutex_m (0.2.0)
45
+ pagy (5.10.1)
46
+ activesupport
47
+ parallel (1.23.0)
48
+ parser (3.2.2.4)
49
+ ast (~> 2.4.1)
50
+ racc
51
+ pry (0.14.2)
52
+ coderay (~> 1.1)
53
+ method_source (~> 1.0)
54
+ racc (1.7.3)
55
+ rack (3.0.8)
56
+ rainbow (3.1.1)
57
+ rake-manifest (0.2.3)
58
+ regexp_parser (2.8.2)
59
+ rexml (3.2.6)
60
+ rspec (3.12.0)
61
+ rspec-core (~> 3.12.0)
62
+ rspec-expectations (~> 3.12.0)
63
+ rspec-mocks (~> 3.12.0)
64
+ rspec-core (3.12.2)
65
+ rspec-support (~> 3.12.0)
66
+ rspec-expectations (3.12.3)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.12.0)
69
+ rspec-mocks (3.12.6)
70
+ diff-lcs (>= 1.2.0, < 2.0)
71
+ rspec-support (~> 3.12.0)
72
+ rspec-support (3.12.1)
73
+ rubocop (1.57.2)
74
+ json (~> 2.3)
75
+ language_server-protocol (>= 3.17.0)
76
+ parallel (~> 1.10)
77
+ parser (>= 3.2.2.4)
78
+ rainbow (>= 2.2.2, < 4.0)
79
+ regexp_parser (>= 1.8, < 3.0)
80
+ rexml (>= 3.2.5, < 4.0)
81
+ rubocop-ast (>= 1.28.1, < 2.0)
82
+ ruby-progressbar (~> 1.7)
83
+ unicode-display_width (>= 2.4.0, < 3.0)
84
+ rubocop-ast (1.30.0)
85
+ parser (>= 3.2.1.0)
86
+ rubocop-capybara (2.19.0)
87
+ rubocop (~> 1.41)
88
+ rubocop-factory_bot (2.24.0)
89
+ rubocop (~> 1.33)
90
+ rubocop-performance (1.19.1)
91
+ rubocop (>= 1.7.0, < 2.0)
92
+ rubocop-ast (>= 0.4.0)
93
+ rubocop-rspec (2.25.0)
94
+ rubocop (~> 1.40)
95
+ rubocop-capybara (~> 2.17)
96
+ rubocop-factory_bot (~> 2.22)
97
+ ruby-progressbar (1.13.0)
98
+ ruby2_keywords (0.0.5)
99
+ standard (1.32.0)
100
+ language_server-protocol (~> 3.17.0.2)
101
+ lint_roller (~> 1.0)
102
+ rubocop (~> 1.57.2)
103
+ standard-custom (~> 1.0.0)
104
+ standard-performance (~> 1.2)
105
+ standard-custom (1.0.2)
106
+ lint_roller (~> 1.0)
107
+ rubocop (~> 1.50)
108
+ standard-performance (1.2.1)
109
+ lint_roller (~> 1.1)
110
+ rubocop-performance (~> 1.19.1)
111
+ thor (1.3.0)
112
+ tzinfo (2.0.6)
113
+ concurrent-ruby (~> 1.0)
114
+ unicode-display_width (2.5.0)
115
+
116
+ PLATFORMS
117
+ x86_64-linux
118
+
119
+ DEPENDENCIES
120
+ activesupport
121
+ esse (~> 0.2.4)
122
+ esse-pagy!
123
+ esse-rspec (~> 0.0.1)
124
+ pagy (~> 5.10, >= 5.10.1)
125
+ pry
126
+ rack
127
+ rake-manifest
128
+ rspec
129
+ rubocop
130
+ rubocop-performance
131
+ rubocop-rspec
132
+ standard
133
+
134
+ BUNDLED WITH
135
+ 2.3.26
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Marcos G. Zimmermann
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Esse Pagy Extension
2
+
3
+ This gem is a [esse](https://github.com/marcosgz/esse) plugin for the [pagy](https://github.com/ddnexus/pagy) pagination.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'esse-pagy'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ # Single index
23
+ query = UsersIndex.pagy_search(body: { ... })
24
+
25
+ # Multiple indexes
26
+ query = Esse.cluster.pagy_search(CitiesIndex, CountiesIndex, body: { ... })
27
+ query = Esse.cluster.pagy_search('esse_geos_*', body: { ... })
28
+
29
+ # paginate it
30
+ @pagy, @response = pagy_esse(collection, items: 10)
31
+ ```
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake none` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marcosgz/esse-pagy.
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/lib/esse/pagy.rb ADDED
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "esse"
4
+ require "pagy"
5
+
6
+ ::Pagy::DEFAULT[:esse_search] ||= :search
7
+ ::Pagy::DEFAULT[:esse_pagy_search] ||= :pagy_search
8
+
9
+ # I'll try to move this to the `pagy` gem. But we need to wait for the `pagy` author to accept the PR.
10
+ # @see https://github.com/ddnexus/pagy/blob/master/lib/pagy/extras/elasticsearch_rails.rb
11
+
12
+ module Esse
13
+ module Pagy
14
+ module IndexSearch
15
+ def pagy_esse(*args, &block)
16
+ kwargs = extract_search_options!(args)
17
+ [cluster, self, kwargs, block].tap do |args|
18
+ args.define_singleton_method(:method_missing) { |*a| args += a }
19
+ end
20
+ end
21
+ alias_method ::Pagy::DEFAULT[:esse_pagy_search], :pagy_esse
22
+ end
23
+
24
+ module ClusterSearch
25
+ def pagy_esse(*indices, **kwargs, &block)
26
+ [self, indices, kwargs, block].tap do |args|
27
+ args.define_singleton_method(:method_missing) { |*a| args += a }
28
+ end
29
+ end
30
+ alias_method ::Pagy::DEFAULT[:esse_pagy_search], :pagy_esse
31
+ end
32
+
33
+ module ClassMethods
34
+ def new_from_esse(query, vars = {})
35
+ vars[:count] = query.response.total
36
+ vars[:page] = (query.offset_value / query.limit_value.to_f).ceil + 1
37
+ vars[:items] = query.limit_value
38
+ ::Pagy.new(vars)
39
+ end
40
+ end
41
+
42
+ # Add specialized backend methods to paginate Esse::Search::Query
43
+ module Backend
44
+ private
45
+
46
+ # Return Pagy object and query
47
+ def pagy_esse(pagy_search_args, vars = {})
48
+ cluster, indices, kwargs, block, *called = pagy_search_args
49
+ vars = pagy_esse_get_vars(nil, vars)
50
+ query = cluster.send(::Pagy::DEFAULT[:esse_search], *indices, **kwargs, &block)
51
+ .limit(vars[:items])
52
+ .offset(vars[:items] * (vars[:page] - 1))
53
+ vars[:count] = query.response.total
54
+
55
+ pagy = ::Pagy.new(vars)
56
+ # with :last_page overflow we need to re-run the method in order to get the hits
57
+ return pagy_esse(pagy_search_args, vars.merge(page: pagy.page)) \
58
+ if defined?(::Pagy::OverflowExtra) && pagy.overflow? && pagy.vars[:overflow] == :last_page
59
+
60
+ [pagy, called.empty? ? query : query.send(*called)]
61
+ end
62
+
63
+ # Sub-method called only by #pagy_esse: here for easy customization of variables by overriding
64
+ # the _query argument is not available when the method is called
65
+ def pagy_esse_get_vars(_query, vars)
66
+ pagy_set_items_from_params(vars) if defined?(ItemsExtra)
67
+ vars[:items] ||= ::Pagy::DEFAULT[:items]
68
+ vars[:page] ||= (params[vars[:page_param] || ::Pagy::DEFAULT[:page_param]] || 1).to_i
69
+ vars
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ ::Pagy::Backend.prepend(Esse::Pagy::Backend)
76
+ ::Pagy.extend(Esse::Pagy::ClassMethods)
77
+ ::Esse::Index.extend(Esse::Pagy::IndexSearch)
78
+ ::Esse::Cluster.prepend(Esse::Pagy::ClusterSearch)
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: esse-pagy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marcos G. Zimmermann
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: esse
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: pagy
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: standard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Pagy extensions for Esse
126
+ email:
127
+ - mgzmaster@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".rubocop.yml"
133
+ - CHANGELOG.md
134
+ - Gemfile
135
+ - Gemfile.lock
136
+ - LICENSE
137
+ - README.md
138
+ - lib/esse/pagy.rb
139
+ homepage: https://github.com/marcosgz/esse-pagy
140
+ licenses:
141
+ - MIT
142
+ metadata:
143
+ homepage_uri: https://github.com/marcosgz/esse-pagy
144
+ source_code_uri: https://github.com/marcosgz/esse-pagy
145
+ changelog_uri: https://github.com/marcosgz/esse-pagy/blob/main/CHANGELOG.md
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: 2.5.0
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubygems_version: 3.1.6
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: Pagy extensions for Esse
165
+ test_files: []