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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2fbbf6a8d97c83f3d098f3b13d93039491698409623d0137e0b170c83dedd58d
4
- data.tar.gz: 9619799961e2416db17aca506f6ef596acd621b3fc1339aa82679b779d3f79e8
3
+ metadata.gz: a0ae2fd0943ca59c70d7f10c8f0c7c48d9cac20fddd65af6c0f255a9352c78a2
4
+ data.tar.gz: 433dddd946b33c7677d3a65ce123c7cc78a5bd1f4defb67b8b2a8b5dc773e6e1
5
5
  SHA512:
6
- metadata.gz: 577f3b00606d238e20a9d24075a92b9b5cdc10f170637e4e6bf6dc58db3bd04bf5de13a75da050af0b7a421d1dfe6bc91b4020188f38051394c39b81133b2fa0
7
- data.tar.gz: abd2108a7892aa866ffc8d6a86545b61df42ce7b0c10af079e4272f5194e74be5f3c7146ed3ed671a96ea5eb6240edeabe77da8e51ab675b2a05427212bb2adf
6
+ metadata.gz: 549fe65cf139efb23f0ea3cf127091e835f4cdfe1f7e48d6700d4ceae0b436d0375ad60b906075d8e79f8a56439a143c294af012706e631d292e442d2572bc35
7
+ data.tar.gz: '009952b67ce09720ed1d250fb1337c9fb053661c7e45427c30e144dcab0d875673ad3a2eed933560b7dfebc70929a162ad075b35e751c3d55138dfd146498877'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.0.0
4
+
5
+ * Replace chain feature with coactive.
6
+
3
7
  ## 1.2.0
4
8
 
5
9
  * Add chain feature.
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
- #### Chain
144
+ #### Coactors
145
145
 
146
- You can chain multiple finders by using `chain`. For example:
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
- chain NameFinder, AgeFinder
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
- You can also use method or block to find finder class dynamically:
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
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "activesupport", ">= 5.0"
21
+ spec.add_dependency "coactive", ">= 0.1"
21
22
 
22
23
  spec.add_development_dependency "rails", ">= 5.0"
23
24
  spec.add_development_dependency "sqlite3"
@@ -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 'chain'
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 Chain
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IIFinder
4
- VERSION = '1.2.0'
4
+ VERSION = '2.0.0'
5
5
  end
data/lib/ii_finder.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'active_support'
2
+ require 'coactive'
2
3
 
3
4
  require 'ii_finder/version'
4
5
  require 'ii_finder/config'
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: 1.2.0
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-08 00:00:00.000000000 Z
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/chain.rb
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.1.2
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
@@ -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