findit 1.1.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.drone.yml +86 -0
- data/.gitignore +1 -0
- data/Appraisals +33 -10
- data/CHANGELOG.md +40 -0
- data/Gemfile +0 -1
- data/README.md +125 -4
- data/dip.yml +46 -0
- data/docker-compose.development.yml +12 -0
- data/docker-compose.drone.yml +7 -0
- data/docker-compose.yml +9 -0
- data/findit.gemspec +5 -5
- data/lib/findit.rb +3 -0
- data/lib/findit/cache.rb +87 -0
- data/lib/findit/collections.rb +3 -19
- data/lib/findit/single.rb +63 -0
- data/lib/findit/version.rb +1 -1
- data/lib/findit/will_paginate.rb +9 -0
- metadata +68 -60
- data/Makefile +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a8a4312793f6f42a65341ed111881e256230f35
|
4
|
+
data.tar.gz: c8a38afe7a521f7663915b1bfac93fc1d54257c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d8fd66b0123e72b5c08f08b520d243c63cf1b1953f64cd06d89ce58d6c0aba245bfe3ad1a111fe84bbb44fe997aaa94141d6c941cb0aedfc8873281935d61e7
|
7
|
+
data.tar.gz: 7650158362ba60928cb1302c2f6202ffaeb91907b88d496306337e9f5cfbdcbf9685fdedd133d548933f6fba9b8024ac58e9e9711418dc88d8729baa3b791775
|
data/.drone.yml
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
name: build
|
2
|
+
|
3
|
+
kind: pipeline
|
4
|
+
type: docker
|
5
|
+
|
6
|
+
volumes:
|
7
|
+
- name: rubygems
|
8
|
+
host:
|
9
|
+
path: /home/data/drone/rubygems
|
10
|
+
- name: images
|
11
|
+
host:
|
12
|
+
path: /home/data/drone/images
|
13
|
+
- name: bundle
|
14
|
+
host:
|
15
|
+
path: /home/data/drone/gems
|
16
|
+
- name: keys
|
17
|
+
host:
|
18
|
+
path: /home/data/drone/key_cache
|
19
|
+
|
20
|
+
spec_step_common: &spec_step_common
|
21
|
+
image: abakpress/dind-testing:1.0.3
|
22
|
+
pull: if-not-exists
|
23
|
+
privileged: true
|
24
|
+
volumes:
|
25
|
+
- name: images
|
26
|
+
path: /images
|
27
|
+
- name: bundle
|
28
|
+
path: /bundle
|
29
|
+
- name: keys
|
30
|
+
path: /ssh_keys
|
31
|
+
commands:
|
32
|
+
- prepare-build
|
33
|
+
|
34
|
+
- fetch-images
|
35
|
+
--image whilp/ssh-agent
|
36
|
+
--image abakpress/ruby-app:$RUBY_IMAGE_TAG
|
37
|
+
|
38
|
+
- dip ssh add -T -v /ssh_keys -k /ssh_keys/id_rsa
|
39
|
+
- dip provision
|
40
|
+
- dip rspec
|
41
|
+
|
42
|
+
steps:
|
43
|
+
- name: Tests Ruby 2.2
|
44
|
+
environment:
|
45
|
+
COMPOSE_FILE_EXT: drone
|
46
|
+
DOCKER_RUBY_VERSION: 2.2
|
47
|
+
RUBY_IMAGE_TAG: 2.2-latest
|
48
|
+
RAILS_ENV: test
|
49
|
+
<<: *spec_step_common
|
50
|
+
|
51
|
+
- name: Tests Ruby 2.3
|
52
|
+
environment:
|
53
|
+
COMPOSE_FILE_EXT: drone
|
54
|
+
DOCKER_RUBY_VERSION: 2.3
|
55
|
+
RUBY_IMAGE_TAG: 2.3-latest
|
56
|
+
RAILS_ENV: test
|
57
|
+
<<: *spec_step_common
|
58
|
+
|
59
|
+
- name: Tests Ruby 2.4
|
60
|
+
environment:
|
61
|
+
COMPOSE_FILE_EXT: drone
|
62
|
+
DOCKER_RUBY_VERSION: 2.4
|
63
|
+
RUBY_IMAGE_TAG: 2.4-latest
|
64
|
+
RAILS_ENV: test
|
65
|
+
<<: *spec_step_common
|
66
|
+
|
67
|
+
- name: Tests Ruby 2.5
|
68
|
+
environment:
|
69
|
+
COMPOSE_FILE_EXT: drone
|
70
|
+
DOCKER_RUBY_VERSION: 2.5
|
71
|
+
RUBY_IMAGE_TAG: 2.5-latest
|
72
|
+
RAILS_ENV: test
|
73
|
+
<<: *spec_step_common
|
74
|
+
|
75
|
+
- name: release
|
76
|
+
image: abakpress/gem-publication:latest
|
77
|
+
pull: if-not-exists
|
78
|
+
when:
|
79
|
+
event: push
|
80
|
+
branch: master
|
81
|
+
status: success
|
82
|
+
volumes:
|
83
|
+
- name: rubygems
|
84
|
+
path: /root/.gem
|
85
|
+
commands:
|
86
|
+
- release-gem --public
|
data/.gitignore
CHANGED
data/Appraisals
CHANGED
@@ -1,20 +1,43 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
if RUBY_VERSION < '2.4'
|
2
|
+
appraise 'rails4.0' do
|
3
|
+
gem 'activesupport', '~> 4.0.0'
|
4
|
+
gem 'sqlite3', '~> 1.3.6'
|
5
|
+
end
|
6
|
+
|
7
|
+
appraise 'rails4.1' do
|
8
|
+
gem 'activesupport', '~> 4.1.0'
|
9
|
+
gem 'sqlite3', '~> 1.3.6'
|
10
|
+
end
|
3
11
|
end
|
4
12
|
|
5
|
-
appraise '
|
6
|
-
gem '
|
13
|
+
appraise 'rails4.2' do
|
14
|
+
gem 'activesupport', '~> 4.2.0'
|
15
|
+
gem 'sqlite3', '~> 1.3.6'
|
7
16
|
end
|
8
17
|
|
9
|
-
appraise '
|
10
|
-
gem '
|
18
|
+
appraise 'rails5.0' do
|
19
|
+
gem 'activesupport', '~> 5.0.0'
|
20
|
+
gem 'sqlite3', '~> 1.3.6'
|
11
21
|
end
|
12
22
|
|
13
|
-
appraise '
|
14
|
-
gem '
|
23
|
+
appraise 'rails5.1' do
|
24
|
+
gem 'activesupport', '~> 5.1.0'
|
25
|
+
gem 'sqlite3', '~> 1.3.6'
|
15
26
|
end
|
16
27
|
|
17
|
-
appraise '
|
18
|
-
gem '
|
28
|
+
appraise 'rails5.2' do
|
29
|
+
gem 'activesupport', '~> 5.2.0'
|
30
|
+
gem 'sqlite3', '~> 1.3.6'
|
19
31
|
end
|
20
32
|
|
33
|
+
if RUBY_VERSION >= '2.5'
|
34
|
+
appraise 'rails6.0' do
|
35
|
+
gem 'activesupport', '~> 6.0.0'
|
36
|
+
gem 'sqlite3', '~> 1.4'
|
37
|
+
end
|
38
|
+
|
39
|
+
appraise 'rails6.1' do
|
40
|
+
gem 'activesupport', '~> 6.1.0'
|
41
|
+
gem 'sqlite3', '~> 1.4'
|
42
|
+
end
|
43
|
+
end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# v1.4.1
|
2
|
+
|
3
|
+
* 2021-08-06 [0941afd](../../commit/0941afd) - __(TamarinEA)__ Release 1.4.1
|
4
|
+
* 2021-08-06 [9d06ecf](../../commit/9d06ecf) - __(TamarinEA)__ chore: test ruby 2.2-2.5 and rails 4.0-6.1
|
5
|
+
* 2018-05-29 [3fd7608](../../commit/3fd7608) - __(Pavel Galkin)__ fix: expire_in -> expires_in typo
|
6
|
+
Из поисков по коду как я понял expires_in это верный вариант
|
7
|
+
|
8
|
+
https://github.com/sorentwo/readthis/blob/v2.0.2/lib/readthis/cache.rb#L395
|
9
|
+
|
10
|
+
# v1.4.0
|
11
|
+
|
12
|
+
* 2017-05-03 [fd29452](../../commit/fd29452) - __(evseevleo)__ feat(collection): delegate :shift
|
13
|
+
* 2017-04-03 [92e5b37](../../commit/92e5b37) - __(Denis Korobicyn)__ Release 1.3.0
|
14
|
+
|
15
|
+
# v1.3.0
|
16
|
+
|
17
|
+
* 2017-03-31 [51de445](../../commit/51de445) - __(Denis Korobicyn)__ feature: cache extension
|
18
|
+
* 2017-03-30 [7e85787](../../commit/7e85787) - __(Denis Korobicyn)__ feature: single extension
|
19
|
+
* 2017-03-30 [fa2445f](../../commit/fa2445f) - __(Denis Korobicyn)__ chore: add drone CI
|
20
|
+
|
21
|
+
# v1.2.0
|
22
|
+
|
23
|
+
* 2016-05-10 [ce9751b](../../commit/ce9751b) - __(Denis Korobicyn)__ feature: will_paginate integration (#5)
|
24
|
+
|
25
|
+
# v1.1.0
|
26
|
+
|
27
|
+
* 2016-05-06 [cc5c612](../../commit/cc5c612) - __(Denis Korobicyn)__ feature: delegate to_a, to_ary to call (#4)
|
28
|
+
|
29
|
+
# v1.0.0
|
30
|
+
|
31
|
+
* 2016-05-05 [222dc6e](../../commit/222dc6e) - __(Denis Korobicyn)__ version 1.0.0
|
32
|
+
* 2016-05-05 [baffa09](../../commit/baffa09) - __(Denis Korobicyn)__ feature: removed `data`, and pure virtual method - `find` (#3)
|
33
|
+
* 2016-05-05 [274a7af](../../commit/274a7af) - __(Denis Korobicyn)__ fix: cache key with namespace of class name (#2)
|
34
|
+
|
35
|
+
# v0.1.0
|
36
|
+
|
37
|
+
* 2016-05-04 [1d8e898](../../commit/1d8e898) - __(Denis Korobicyn)__ Init commit (#1)
|
38
|
+
* Init commit
|
39
|
+
|
40
|
+
* 2016-04-26 [56d5ce8](../../commit/56d5ce8) - __(Artem Napolskih)__ Initial commit
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -155,11 +155,132 @@ class PostsController < ApplicationController
|
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
|
-
#/app/views/posts/index.html.
|
159
|
-
<% cache(@posts,
|
160
|
-
<%=render 'post'
|
158
|
+
#/app/views/posts/index.html.erb
|
159
|
+
<% cache(@posts, expires_in: 30.minutes) do %>
|
160
|
+
<%=render 'post', collection: @posts, as: :post%> # it will automaticly iterate over finder results by each method
|
161
|
+
```
|
162
|
+
|
163
|
+
### WillPaginate
|
164
|
+
|
165
|
+
It adds delegation of [will_paginate](https://github.com/mislav/will_paginate) methods to finder.
|
166
|
+
|
167
|
+
Example usage:
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
# app/finders/post_finder.rb
|
171
|
+
class PostFinder
|
172
|
+
include Findit::Collection
|
173
|
+
include Findit::WillPaginate
|
174
|
+
|
175
|
+
cache_key do
|
176
|
+
[@page, @per_page]
|
177
|
+
end
|
178
|
+
|
179
|
+
def initialize(page, per_page)
|
180
|
+
@page = page
|
181
|
+
@per_page = per_page
|
182
|
+
end
|
183
|
+
|
184
|
+
private
|
185
|
+
|
186
|
+
def find
|
187
|
+
scope = Post.paginate(per_page: per_page, page: page)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# app/controllers/posts_controller.rb
|
192
|
+
|
193
|
+
class PostsController < ApplicationController
|
194
|
+
def index
|
195
|
+
@posts = PostFinder.new(params[:page], params[:per_page])
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# app/views/posts/index.html.erb
|
200
|
+
<% cache(@posts, expires_in: 30.minutes) do %>
|
201
|
+
<%= render 'post', collection: @posts, as: :post %>
|
202
|
+
<%= will_paginate @posts %>
|
203
|
+
```
|
204
|
+
|
205
|
+
### Single
|
206
|
+
|
207
|
+
Adds DSL for cache_key on Finder with single element to find.
|
208
|
+
|
209
|
+
Example usage:
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
# app/finders/post_finder.rb
|
213
|
+
class PostsFinder
|
214
|
+
include Findit::Single
|
215
|
+
|
216
|
+
cache_key do
|
217
|
+
@user
|
218
|
+
end
|
219
|
+
|
220
|
+
def initialize(user)
|
221
|
+
@user = user
|
222
|
+
end
|
223
|
+
|
224
|
+
private
|
225
|
+
|
226
|
+
def find
|
227
|
+
Post.where(user: user).last
|
228
|
+
end
|
229
|
+
end
|
230
|
+
```
|
231
|
+
|
232
|
+
### Cache
|
233
|
+
|
234
|
+
Extends finder with cache possibility. Every call of `call` method will be cached in `Rails.cache`.
|
235
|
+
Method `cache options` allows you to add custom options like `expires_in` or `tags` to `Rails.cache.fetch`.
|
236
|
+
If you want to disable cache dependent of initialization arguments, you can use `cache?` DSL method.
|
237
|
+
|
238
|
+
All in one Example:
|
239
|
+
```ruby
|
240
|
+
# app/finders/post_finder.rb
|
241
|
+
class CachedPostsFinder
|
242
|
+
include Findit::Single
|
243
|
+
include Findit::Cache
|
244
|
+
|
245
|
+
cache_key do
|
246
|
+
@user
|
247
|
+
end
|
248
|
+
|
249
|
+
cache_options do
|
250
|
+
{expires_in: 15.minutes} # This will be directly passed to Rails.cache.fetch
|
251
|
+
end
|
252
|
+
|
253
|
+
def initialize(user)
|
254
|
+
@user = user
|
255
|
+
end
|
256
|
+
|
257
|
+
private
|
258
|
+
|
259
|
+
def find
|
260
|
+
Post.where(user: user)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
```
|
264
|
+
|
265
|
+
To disable cache for some reasone you can call special method without_cache:
|
266
|
+
|
267
|
+
```ruby
|
268
|
+
CachedFinder.new(user).without_cache.load # no cache
|
269
|
+
|
270
|
+
CachedFinder.new(user).load - # will perform cache operations
|
271
|
+
```
|
272
|
+
|
273
|
+
|
274
|
+
If you want this functionality on Collections finder you can add extension `Findit::Collections` alongside with Cache:
|
275
|
+
```ruby
|
276
|
+
class SomeFinder
|
277
|
+
include Findit::Collections
|
278
|
+
include Findit::Cache
|
279
|
+
|
280
|
+
...
|
281
|
+
end
|
161
282
|
```
|
162
283
|
|
163
284
|
## Contributing
|
164
285
|
|
165
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
286
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/abak-press/findit.
|
data/dip.yml
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
version: '1'
|
2
|
+
|
3
|
+
environment:
|
4
|
+
DOCKER_RUBY_VERSION: 2.5
|
5
|
+
RUBY_IMAGE_TAG: 2.5-latest
|
6
|
+
COMPOSE_FILE_EXT: development
|
7
|
+
RAILS_ENV: test
|
8
|
+
|
9
|
+
compose:
|
10
|
+
files:
|
11
|
+
- docker-compose.yml
|
12
|
+
- docker-compose.${COMPOSE_FILE_EXT}.yml
|
13
|
+
|
14
|
+
interaction:
|
15
|
+
sh:
|
16
|
+
service: app
|
17
|
+
|
18
|
+
irb:
|
19
|
+
service: app
|
20
|
+
command: irb
|
21
|
+
|
22
|
+
bundle:
|
23
|
+
service: app
|
24
|
+
command: bundle
|
25
|
+
|
26
|
+
rake:
|
27
|
+
service: app
|
28
|
+
command: bundle exec rake
|
29
|
+
|
30
|
+
appraisal:
|
31
|
+
service: app
|
32
|
+
command: bundle exec appraisal
|
33
|
+
|
34
|
+
rspec:
|
35
|
+
service: app
|
36
|
+
command: bundle exec appraisal bundle exec rspec
|
37
|
+
|
38
|
+
clean:
|
39
|
+
service: app
|
40
|
+
command: rm -f Gemfile.lock gemfiles/*.gemfile.*
|
41
|
+
|
42
|
+
provision:
|
43
|
+
- docker volume create --name bundler_data
|
44
|
+
- dip clean
|
45
|
+
- dip bundle install
|
46
|
+
- dip appraisal install
|
data/docker-compose.yml
ADDED
data/findit.gemspec
CHANGED
@@ -17,15 +17,15 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_runtime_dependency 'activesupport', '>=
|
20
|
+
spec.add_runtime_dependency 'activesupport', '>= 4.0'
|
21
21
|
|
22
|
-
spec.add_development_dependency
|
22
|
+
spec.add_development_dependency 'activerecord'
|
23
|
+
spec.add_development_dependency 'will_paginate'
|
23
24
|
spec.add_development_dependency "rspec", ">= 3.2"
|
24
|
-
spec.add_development_dependency "rspec-rails", ">= 3.
|
25
|
+
spec.add_development_dependency "rspec-rails", ">= 3.9.1"
|
25
26
|
spec.add_development_dependency 'combustion', '>= 0.5'
|
26
27
|
spec.add_development_dependency "appraisal", ">= 2.1.0"
|
27
|
-
spec.add_development_dependency 'pry-
|
28
|
-
spec.add_development_dependency 'shoulda-matchers', '< 3.0.0'
|
28
|
+
spec.add_development_dependency 'pry-byebug'
|
29
29
|
spec.add_development_dependency 'simplecov'
|
30
30
|
spec.add_development_dependency 'sqlite3'
|
31
31
|
end
|
data/lib/findit.rb
CHANGED
data/lib/findit/cache.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
#
|
2
|
+
# Example usage:
|
3
|
+
#
|
4
|
+
# #/app/finders/posts_finders.rb
|
5
|
+
# class CachedPostFinder
|
6
|
+
# include Findit::Cache
|
7
|
+
#
|
8
|
+
# cache_key do
|
9
|
+
# [@user.id, @query]
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# cache? do
|
13
|
+
# !@no_cache
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# cache_options do
|
17
|
+
# {expires_in: 15.minutes}
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# private
|
21
|
+
#
|
22
|
+
# def find
|
23
|
+
# scope = scope.where(user_id: @user.id)
|
24
|
+
# scope = scope.where('description like :query', query: @query) if @query.present?
|
25
|
+
# scope
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# #/app/controllers/posts_controller.rb
|
30
|
+
# class PostsController < ApplicationController
|
31
|
+
# def show
|
32
|
+
# @post = CachedPostFinder.new(user: current_user).call
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# #/app/views/posts/index.html.erb
|
37
|
+
# # Already cached in finder itself
|
38
|
+
# <%= render 'post', post: @post%>
|
39
|
+
#
|
40
|
+
# # OR if you call it in another finder
|
41
|
+
# class CommentOnMyLastPostFinder
|
42
|
+
# include Findit::Collections
|
43
|
+
#
|
44
|
+
# def initialize(user)
|
45
|
+
# @user = user
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# private
|
49
|
+
#
|
50
|
+
# def find
|
51
|
+
# last_post.comments
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# def last_post
|
55
|
+
# @post = CachedPostFinder.new(user).call
|
56
|
+
# end
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
module Findit
|
60
|
+
module Cache
|
61
|
+
extend ActiveSupport::Concern
|
62
|
+
|
63
|
+
module ClassMethods
|
64
|
+
def cache_options(&block)
|
65
|
+
define_method(:cache_options) do
|
66
|
+
instance_exec(&block)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
included do
|
72
|
+
set_callback :find, :around do |object, block|
|
73
|
+
if !defined?(@cache) || @cache
|
74
|
+
options = respond_to?(:cache_options) && cache_options
|
75
|
+
@data = Rails.cache.fetch(object.cache_key, options) { block.call }
|
76
|
+
else
|
77
|
+
block.call
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def without_cache
|
83
|
+
@cache = false
|
84
|
+
self
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/findit/collections.rb
CHANGED
@@ -31,7 +31,7 @@
|
|
31
31
|
# end
|
32
32
|
#
|
33
33
|
# #/app/views/posts/index.html.erb
|
34
|
-
# <% cache(@posts, tags: @posts.cache_tags,
|
34
|
+
# <% cache(@posts, tags: @posts.cache_tags, expires_in: @posts.expires_in) do %>
|
35
35
|
# <%= render 'post' colection: @posts, as: :post%>
|
36
36
|
#
|
37
37
|
module Findit
|
@@ -40,24 +40,8 @@ module Findit
|
|
40
40
|
extend ActiveSupport::Concern
|
41
41
|
|
42
42
|
included do
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
module ClassMethods
|
47
|
-
def cache_key(&block)
|
48
|
-
define_method :cache_key do
|
49
|
-
@cache_key ||= ActiveSupport::Cache.expand_cache_key(instance_exec(&block), self.class.name.underscore)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def find
|
55
|
-
end
|
56
|
-
undef :find
|
57
|
-
|
58
|
-
def call
|
59
|
-
return @data if defined?(@data)
|
60
|
-
@data = find
|
43
|
+
include ::Findit::Single
|
44
|
+
delegate :each, :[], :size, :empty?, :to_ary, :to_a, :shift, to: :call
|
61
45
|
end
|
62
46
|
end
|
63
47
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#
|
2
|
+
# Example usage:
|
3
|
+
#
|
4
|
+
# #/app/finders/post_finders.rb
|
5
|
+
# class PostFinder
|
6
|
+
# include Findit::Single
|
7
|
+
#
|
8
|
+
# cache_key do
|
9
|
+
# [@user.id, @query]
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# def initialize(user, options = {})
|
13
|
+
# @user = user
|
14
|
+
# @query = options.fetch(:query)
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# private
|
18
|
+
#
|
19
|
+
# def find
|
20
|
+
# post = scope.find_by('description like :query', query: @query)
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# #/app/controllers/posts_controller.rb
|
25
|
+
# class PostsController < ApplicationController
|
26
|
+
# def show
|
27
|
+
# @post = PostFinder.new(current_user, query: 'some desc')
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# #/app/views/posts/show.html.erb
|
32
|
+
# <% cache(@post, expires_in: 15.minutes) do %>
|
33
|
+
# <%= render 'post', post: @post.load%>
|
34
|
+
#
|
35
|
+
module Findit
|
36
|
+
module Single
|
37
|
+
extend ActiveSupport::Concern
|
38
|
+
|
39
|
+
included do
|
40
|
+
include ActiveSupport::Callbacks
|
41
|
+
define_callbacks :find
|
42
|
+
end
|
43
|
+
|
44
|
+
module ClassMethods
|
45
|
+
def cache_key(&block)
|
46
|
+
define_method :cache_key do
|
47
|
+
@cache_key ||= ActiveSupport::Cache.expand_cache_key(instance_exec(&block), self.class.name.underscore)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def find
|
53
|
+
end
|
54
|
+
undef :find
|
55
|
+
|
56
|
+
def call
|
57
|
+
return @data if defined?(@data)
|
58
|
+
res = run_callbacks(:find) { find }
|
59
|
+
@data ||= res
|
60
|
+
end
|
61
|
+
alias_method :load, :call
|
62
|
+
end
|
63
|
+
end
|
data/lib/findit/version.rb
CHANGED
metadata
CHANGED
@@ -1,155 +1,155 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: findit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Korobicyn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
version_requirements: !ruby/object:Gem::Requirement
|
15
|
-
requirements:
|
16
|
-
- - '>='
|
17
|
-
- !ruby/object:Gem::Version
|
18
|
-
version: '3.1'
|
19
14
|
name: activesupport
|
20
15
|
requirement: !ruby/object:Gem::Requirement
|
21
16
|
requirements:
|
22
|
-
- -
|
17
|
+
- - ">="
|
23
18
|
- !ruby/object:Gem::Version
|
24
|
-
version: '
|
19
|
+
version: '4.0'
|
25
20
|
type: :runtime
|
26
21
|
prerelease: false
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
22
|
version_requirements: !ruby/object:Gem::Requirement
|
29
23
|
requirements:
|
30
|
-
- -
|
24
|
+
- - ">="
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
33
|
-
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
34
29
|
requirement: !ruby/object:Gem::Requirement
|
35
30
|
requirements:
|
36
|
-
- -
|
31
|
+
- - ">="
|
37
32
|
- !ruby/object:Gem::Version
|
38
|
-
version: '
|
33
|
+
version: '0'
|
39
34
|
type: :development
|
40
35
|
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
+
name: will_paginate
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
42
50
|
version_requirements: !ruby/object:Gem::Requirement
|
43
51
|
requirements:
|
44
|
-
- -
|
52
|
+
- - ">="
|
45
53
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
47
56
|
name: rspec
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
58
|
requirements:
|
50
|
-
- -
|
59
|
+
- - ">="
|
51
60
|
- !ruby/object:Gem::Version
|
52
61
|
version: '3.2'
|
53
62
|
type: :development
|
54
63
|
prerelease: false
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
64
|
version_requirements: !ruby/object:Gem::Requirement
|
57
65
|
requirements:
|
58
|
-
- -
|
66
|
+
- - ">="
|
59
67
|
- !ruby/object:Gem::Version
|
60
68
|
version: '3.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
61
70
|
name: rspec-rails
|
62
71
|
requirement: !ruby/object:Gem::Requirement
|
63
72
|
requirements:
|
64
|
-
- -
|
73
|
+
- - ">="
|
65
74
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
75
|
+
version: 3.9.1
|
67
76
|
type: :development
|
68
77
|
prerelease: false
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
78
|
version_requirements: !ruby/object:Gem::Requirement
|
71
79
|
requirements:
|
72
|
-
- -
|
80
|
+
- - ">="
|
73
81
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
82
|
+
version: 3.9.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
75
84
|
name: combustion
|
76
85
|
requirement: !ruby/object:Gem::Requirement
|
77
86
|
requirements:
|
78
|
-
- -
|
87
|
+
- - ">="
|
79
88
|
- !ruby/object:Gem::Version
|
80
89
|
version: '0.5'
|
81
90
|
type: :development
|
82
91
|
prerelease: false
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
92
|
version_requirements: !ruby/object:Gem::Requirement
|
85
93
|
requirements:
|
86
|
-
- -
|
94
|
+
- - ">="
|
87
95
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
96
|
+
version: '0.5'
|
97
|
+
- !ruby/object:Gem::Dependency
|
89
98
|
name: appraisal
|
90
99
|
requirement: !ruby/object:Gem::Requirement
|
91
100
|
requirements:
|
92
|
-
- -
|
101
|
+
- - ">="
|
93
102
|
- !ruby/object:Gem::Version
|
94
103
|
version: 2.1.0
|
95
104
|
type: :development
|
96
105
|
prerelease: false
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
106
|
version_requirements: !ruby/object:Gem::Requirement
|
99
107
|
requirements:
|
100
|
-
- -
|
108
|
+
- - ">="
|
101
109
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
103
|
-
name: pry-debugger
|
104
|
-
requirement: !ruby/object:Gem::Requirement
|
105
|
-
requirements:
|
106
|
-
- - '>='
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
version: '0'
|
109
|
-
type: :development
|
110
|
-
prerelease: false
|
110
|
+
version: 2.1.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
|
113
|
-
requirements:
|
114
|
-
- - <
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: 3.0.0
|
117
|
-
name: shoulda-matchers
|
112
|
+
name: pry-byebug
|
118
113
|
requirement: !ruby/object:Gem::Requirement
|
119
114
|
requirements:
|
120
|
-
- -
|
115
|
+
- - ">="
|
121
116
|
- !ruby/object:Gem::Version
|
122
|
-
version:
|
117
|
+
version: '0'
|
123
118
|
type: :development
|
124
119
|
prerelease: false
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
120
|
version_requirements: !ruby/object:Gem::Requirement
|
127
121
|
requirements:
|
128
|
-
- -
|
122
|
+
- - ">="
|
129
123
|
- !ruby/object:Gem::Version
|
130
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
131
126
|
name: simplecov
|
132
127
|
requirement: !ruby/object:Gem::Requirement
|
133
128
|
requirements:
|
134
|
-
- -
|
129
|
+
- - ">="
|
135
130
|
- !ruby/object:Gem::Version
|
136
131
|
version: '0'
|
137
132
|
type: :development
|
138
133
|
prerelease: false
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
134
|
version_requirements: !ruby/object:Gem::Requirement
|
141
135
|
requirements:
|
142
|
-
- -
|
136
|
+
- - ">="
|
143
137
|
- !ruby/object:Gem::Version
|
144
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
145
140
|
name: sqlite3
|
146
141
|
requirement: !ruby/object:Gem::Requirement
|
147
142
|
requirements:
|
148
|
-
- -
|
143
|
+
- - ">="
|
149
144
|
- !ruby/object:Gem::Version
|
150
145
|
version: '0'
|
151
146
|
type: :development
|
152
147
|
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
153
|
description:
|
154
154
|
email:
|
155
155
|
- deniskorobitcin@gmail.com
|
@@ -157,19 +157,27 @@ executables: []
|
|
157
157
|
extensions: []
|
158
158
|
extra_rdoc_files: []
|
159
159
|
files:
|
160
|
-
- .
|
160
|
+
- ".drone.yml"
|
161
|
+
- ".gitignore"
|
161
162
|
- Appraisals
|
163
|
+
- CHANGELOG.md
|
162
164
|
- Gemfile
|
163
|
-
- Makefile
|
164
165
|
- README.md
|
165
166
|
- Rakefile
|
166
167
|
- bin/console
|
167
168
|
- bin/setup
|
168
169
|
- config.ru
|
170
|
+
- dip.yml
|
171
|
+
- docker-compose.development.yml
|
172
|
+
- docker-compose.drone.yml
|
173
|
+
- docker-compose.yml
|
169
174
|
- findit.gemspec
|
170
175
|
- lib/findit.rb
|
176
|
+
- lib/findit/cache.rb
|
171
177
|
- lib/findit/collections.rb
|
178
|
+
- lib/findit/single.rb
|
172
179
|
- lib/findit/version.rb
|
180
|
+
- lib/findit/will_paginate.rb
|
173
181
|
homepage: https://github.com/abak-press/findit
|
174
182
|
licenses: []
|
175
183
|
metadata: {}
|
@@ -179,17 +187,17 @@ require_paths:
|
|
179
187
|
- lib
|
180
188
|
required_ruby_version: !ruby/object:Gem::Requirement
|
181
189
|
requirements:
|
182
|
-
- -
|
190
|
+
- - ">="
|
183
191
|
- !ruby/object:Gem::Version
|
184
192
|
version: '0'
|
185
193
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
194
|
requirements:
|
187
|
-
- -
|
195
|
+
- - ">="
|
188
196
|
- !ruby/object:Gem::Version
|
189
197
|
version: '0'
|
190
198
|
requirements: []
|
191
199
|
rubyforge_project:
|
192
|
-
rubygems_version: 2.
|
200
|
+
rubygems_version: 2.6.1
|
193
201
|
signing_key:
|
194
202
|
specification_version: 4
|
195
203
|
summary: Extensions for Finder classes
|
data/Makefile
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
RAILS_ENV = test
|
2
|
-
BUNDLE_VERSION = 1.11.2
|
3
|
-
BUNDLE = RAILS_ENV=${RAILS_ENV} bundle _${BUNDLE_VERSION}_
|
4
|
-
BUNDLE_OPTIONS = -j 2
|
5
|
-
RSPEC = rspec
|
6
|
-
APPRAISAL = appraisal
|
7
|
-
|
8
|
-
all: test
|
9
|
-
|
10
|
-
test: bundler/install appraisal/install
|
11
|
-
${BUNDLE} exec ${APPRAISAL} ${RSPEC} spec 2>&1
|
12
|
-
|
13
|
-
bundler/install:
|
14
|
-
gem install bundler --version=${BUNDLE_VERSION};
|
15
|
-
${BUNDLE} install ${BUNDLE_OPTIONS}
|
16
|
-
|
17
|
-
appraisal/install:
|
18
|
-
${BUNDLE} exec ${APPRAISAL} install
|
19
|
-
|
20
|
-
clean:
|
21
|
-
rm -f Gemfile.lock
|
22
|
-
rm -rf gemfiles
|
23
|
-
|