ii_finder 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +4 -18
- data/ii_finder.gemspec +1 -0
- data/lib/ii_finder/base.rb +2 -2
- data/lib/ii_finder/coactors.rb +29 -0
- data/lib/ii_finder/version.rb +1 -1
- data/lib/ii_finder.rb +1 -0
- metadata +18 -4
- data/lib/ii_finder/chain.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0ae2fd0943ca59c70d7f10c8f0c7c48d9cac20fddd65af6c0f255a9352c78a2
|
4
|
+
data.tar.gz: 433dddd946b33c7677d3a65ce123c7cc78a5bd1f4defb67b8b2a8b5dc773e6e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 549fe65cf139efb23f0ea3cf127091e835f4cdfe1f7e48d6700d4ceae0b436d0375ad60b906075d8e79f8a56439a143c294af012706e631d292e442d2572bc35
|
7
|
+
data.tar.gz: '009952b67ce09720ed1d250fb1337c9fb053661c7e45427c30e144dcab0d875673ad3a2eed933560b7dfebc70929a162ad075b35e751c3d55138dfd146498877'
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -141,9 +141,9 @@ Note that finder does not handle the return value of callback.
|
|
141
141
|
When you want to update `@relation` in the callback,
|
142
142
|
reassign `@relation` or use methods like `where!` or `order!`.
|
143
143
|
|
144
|
-
####
|
144
|
+
#### Coactors
|
145
145
|
|
146
|
-
You can chain multiple finders by using `
|
146
|
+
You can chain multiple finders by using `coact`. For example:
|
147
147
|
|
148
148
|
```ruby
|
149
149
|
class NameFinder < IIFinder::Base
|
@@ -163,28 +163,14 @@ class AgeFinder < IIFinder::Base
|
|
163
163
|
end
|
164
164
|
|
165
165
|
class ItemsFinder < IIFinder::Base
|
166
|
-
|
166
|
+
coact NameFinder, AgeFinder
|
167
167
|
end
|
168
168
|
|
169
169
|
ItemsFinder.call(Item.all, name: 'name', age: 10).to_sql
|
170
170
|
#=> SELECT "items".* FROM "items" WHERE "items"."name" = 'name' AND "items"."age" = 10
|
171
171
|
```
|
172
172
|
|
173
|
-
|
174
|
-
|
175
|
-
```ruby
|
176
|
-
class ItemFinder < IIFinder::Base
|
177
|
-
chain -> { NameFinder }
|
178
|
-
end
|
179
|
-
|
180
|
-
class ItemFinder < IIFinder::Base
|
181
|
-
chain :chain_finder
|
182
|
-
|
183
|
-
def chain_finder
|
184
|
-
NameFinder
|
185
|
-
end
|
186
|
-
end
|
187
|
-
```
|
173
|
+
See [coactive](https://github.com/kanety/coactive) for more `coact` examples:
|
188
174
|
|
189
175
|
### Lookup for model
|
190
176
|
|
data/ii_finder.gemspec
CHANGED
data/lib/ii_finder/base.rb
CHANGED
@@ -5,7 +5,7 @@ require_relative 'parameters'
|
|
5
5
|
require_relative 'callbacks'
|
6
6
|
require_relative 'instrumentation'
|
7
7
|
require_relative 'lookup'
|
8
|
-
require_relative '
|
8
|
+
require_relative 'coactors'
|
9
9
|
|
10
10
|
module IIFinder
|
11
11
|
class Base
|
@@ -14,6 +14,6 @@ module IIFinder
|
|
14
14
|
include Callbacks
|
15
15
|
include Instrumentation
|
16
16
|
include Lookup
|
17
|
-
include
|
17
|
+
include Coactors
|
18
18
|
end
|
19
19
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IIFinder
|
4
|
+
module Coactors
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
include Coactive::Base
|
9
|
+
|
10
|
+
configure_coactive do |config|
|
11
|
+
config.load_paths = ['app/finders']
|
12
|
+
config.class_suffix = 'Finder'
|
13
|
+
config.use_cache = true
|
14
|
+
config.lookup_superclass_until = ['ActiveRecord::Base', 'ActiveModel::Base']
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
alias_method :chain, :coact
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def call
|
23
|
+
coactors.each do |finder|
|
24
|
+
merge_relation!(finder.call(*@_args))
|
25
|
+
end
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/ii_finder/version.rb
CHANGED
data/lib/ii_finder.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ii_finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshikazu Kaneta
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coactive
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rails
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,7 +134,7 @@ files:
|
|
120
134
|
- lib/ii_finder.rb
|
121
135
|
- lib/ii_finder/base.rb
|
122
136
|
- lib/ii_finder/callbacks.rb
|
123
|
-
- lib/ii_finder/
|
137
|
+
- lib/ii_finder/coactors.rb
|
124
138
|
- lib/ii_finder/config.rb
|
125
139
|
- lib/ii_finder/core.rb
|
126
140
|
- lib/ii_finder/errors.rb
|
@@ -149,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
163
|
- !ruby/object:Gem::Version
|
150
164
|
version: '0'
|
151
165
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
166
|
+
rubygems_version: 3.0.3
|
153
167
|
signing_key:
|
154
168
|
specification_version: 4
|
155
169
|
summary: A base finder to support building relations from parameters
|
data/lib/ii_finder/chain.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module IIFinder
|
4
|
-
module Chain
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
class_attribute :_chains
|
9
|
-
self._chains = []
|
10
|
-
end
|
11
|
-
|
12
|
-
def call
|
13
|
-
lookup.each do |finder|
|
14
|
-
merge_relation!(finder.call(*@_args))
|
15
|
-
end
|
16
|
-
super
|
17
|
-
end
|
18
|
-
|
19
|
-
def lookup
|
20
|
-
self.class._chains.map do |finder|
|
21
|
-
if finder.is_a?(Symbol) && respond_to?(finder, true)
|
22
|
-
send(finder)
|
23
|
-
elsif finder.is_a?(Proc)
|
24
|
-
instance_exec(&finder)
|
25
|
-
else
|
26
|
-
finder
|
27
|
-
end
|
28
|
-
end.flatten.compact
|
29
|
-
end
|
30
|
-
|
31
|
-
class_methods do
|
32
|
-
def chain(*finders, &block)
|
33
|
-
self._chains = _chains + finders
|
34
|
-
self._chains << block if block
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|