trailblazer-finder 0.80.1 → 0.91.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trailblazer/finder/activities/prepare_adapter.rb +5 -4
- data/lib/trailblazer/finder/activities/process_adapters.rb +10 -4
- data/lib/trailblazer/finder/base.rb +0 -2
- data/lib/trailblazer/finder/version.rb +1 -1
- data/lib/trailblazer/finder.rb +28 -25
- data/lib/trailblazer/operation/finder.rb +44 -42
- metadata +17 -65
- data/trailblazer-finder.gemspec +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 299e4ce460407b5ae703246c2c0cd3a9306560a3d540be1ded926a1cc892456e
|
4
|
+
data.tar.gz: 470abe97adffcaa66406a2013bae3990ad6a2d82e89132f7cb0ca157b038458e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4585a52d42fc8e86dd0570c2e30e290a1af08ffce6ab965e4ed674011e909006a9bd3c7ec45408a7485536e080b150d90a731e6f37c2e31d2483e6f8be5bf049
|
7
|
+
data.tar.gz: 75a02a268b5ce8d2fa02a47cf3b9f2c5fc90b08f94920c03136c5ec6070b822ce58a1716ea92a99f375b56916433577bc778d9d0e87a2f1049f96c2969223af0
|
@@ -9,16 +9,17 @@ module Trailblazer
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def validate_adapter(_ctx, adapter:, **)
|
12
|
-
|
12
|
+
ORM_ADAPTERS.(adapter.to_s)
|
13
13
|
end
|
14
14
|
|
15
|
-
def invalid?((ctx, _flow_options), **_circuit_options)
|
15
|
+
def invalid?(_e, (ctx, _flow_options), **_circuit_options)
|
16
16
|
(ctx[:errors] ||= []) << {adapter: "The specified adapter are invalid"}
|
17
17
|
end
|
18
18
|
|
19
19
|
step :set_adapter
|
20
|
-
step :
|
21
|
-
|
20
|
+
step Rescue(Dry::Types::ConstraintError, handler: :invalid?) {
|
21
|
+
step :validate_adapter
|
22
|
+
}
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
@@ -17,8 +17,8 @@ module Trailblazer
|
|
17
17
|
def set_paginator(ctx, **)
|
18
18
|
paginator = ctx.dig(:config, :paginator)
|
19
19
|
return true unless paginator
|
20
|
-
return false unless
|
21
|
-
return false unless PAGING_ADAPTERS.
|
20
|
+
return false unless EXT_ORM_ADAPTERS.(ctx[:orm][:adapter])
|
21
|
+
return false unless PAGING_ADAPTERS.(paginator)
|
22
22
|
|
23
23
|
ctx[:orm][:paging] = "Trailblazer::Finder::Adapters::#{paginator}::Paging"
|
24
24
|
true
|
@@ -33,9 +33,15 @@ module Trailblazer
|
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
36
|
+
def invalid_paginator_handler(_e, (ctx, _flow_options), **)
|
37
|
+
invalid_paginator_error(ctx)
|
38
|
+
end
|
39
|
+
|
36
40
|
step :set_adapter, fast_track: true
|
37
|
-
step :
|
38
|
-
|
41
|
+
step Rescue(Dry::Types::ConstraintError, handler: :invalid_paginator_handler) {
|
42
|
+
step :set_paginator
|
43
|
+
fail :invalid_paginator_error
|
44
|
+
}
|
39
45
|
end
|
40
46
|
end
|
41
47
|
end
|
data/lib/trailblazer/finder.rb
CHANGED
@@ -5,37 +5,40 @@ require "trailblazer"
|
|
5
5
|
require "dry-types"
|
6
6
|
require "ostruct"
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
8
|
+
require_relative "finder/utils/array"
|
9
|
+
require_relative "finder/utils/hash"
|
10
|
+
require_relative "finder/utils/string"
|
11
|
+
require_relative "finder/utils/splitter"
|
12
|
+
require_relative "finder/utils/extra"
|
13
|
+
require_relative "finder/adapters/active_record/predicates"
|
14
|
+
require_relative "finder/adapters/active_record/paging"
|
15
|
+
require_relative "finder/adapters/active_record/sorting"
|
16
|
+
require_relative "finder/adapters/kaminari/paging"
|
17
|
+
require_relative "finder/adapters/will_paginate/paging"
|
18
|
+
require_relative "finder/adapters/sequel/predicates"
|
19
|
+
require_relative "finder/adapters/sequel/paging"
|
20
|
+
require_relative "finder/adapters/sequel/sorting"
|
21
|
+
require_relative "finder/adapters/basic/predicates"
|
22
|
+
require_relative "finder/adapters/basic/paging"
|
23
|
+
require_relative "finder/adapters/basic/sorting"
|
24
|
+
require_relative "finder/activities/prepare"
|
25
|
+
require_relative "finder/activities/process"
|
26
|
+
require_relative "finder/activities/find"
|
27
|
+
require_relative "finder/helpers/basic"
|
28
|
+
require_relative "finder/helpers/sorting"
|
29
|
+
require_relative "finder/dsl"
|
30
|
+
require_relative "finder/find"
|
31
|
+
require_relative "finder/base"
|
32
|
+
require_relative "operation/finder"
|
33
33
|
|
34
34
|
module Trailblazer
|
35
35
|
class Finder
|
36
36
|
module Types
|
37
37
|
include Dry.Types(default: :nominal)
|
38
38
|
end
|
39
|
+
EXT_ORM_ADAPTERS = Types::Strict::String.enum("ActiveRecord", "Sequel")
|
40
|
+
ORM_ADAPTERS = EXT_ORM_ADAPTERS | Types::Strict::String.enum("Basic")
|
41
|
+
PAGING_ADAPTERS = Types::Strict::String.enum("Kaminari", "WillPaginate")
|
39
42
|
|
40
43
|
include Base
|
41
44
|
end
|
@@ -1,55 +1,57 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
class Finder
|
15
|
-
def call(ctx, **options)
|
16
|
-
builder = Finder::Builder.new
|
17
|
-
ctx[:finder] = finder = builder.call(options, options[:params])
|
18
|
-
ctx[:model] = finder # Don't like it, but somehow it's needed if contracts are loaded
|
19
|
-
ctx[:"result.finder"] = Trailblazer::Operation::Result.new(!finder.nil?, {})
|
20
|
-
|
21
|
-
ctx[:"result.finder"].success?
|
1
|
+
module Trailblazer
|
2
|
+
class Operation
|
3
|
+
def self.Finder(finder_class, action = nil, entity = nil)
|
4
|
+
task = Trailblazer::Activity::Circuit::TaskAdapter.for_step(Finder.new, binary: true)
|
5
|
+
injections = [
|
6
|
+
:params,
|
7
|
+
{:"finder.class" => ->(*) { finder_class }},
|
8
|
+
{:"finder.entity" => ->(*) { entity }},
|
9
|
+
{:"finder.action" => ->(*) { action }}
|
10
|
+
]
|
11
|
+
|
12
|
+
{task: task, id: "finder.build", inject: injections}
|
22
13
|
end
|
23
14
|
|
24
|
-
class
|
25
|
-
def call(
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
15
|
+
class Finder
|
16
|
+
def call(ctx, **options)
|
17
|
+
builder = Finder::Builder.new
|
18
|
+
ctx[:finder] = finder = builder.call(options, options[:params])
|
19
|
+
ctx[:model] = finder # Don't like it, but somehow it's needed if contracts are loaded
|
20
|
+
ctx[:"result.finder"] = Trailblazer::Operation::Result.new(!finder.nil?, {})
|
30
21
|
|
31
|
-
|
22
|
+
ctx[:"result.finder"].success?
|
32
23
|
end
|
33
24
|
|
34
|
-
|
25
|
+
class Builder
|
26
|
+
def call(options, params)
|
27
|
+
finder_class = options[:"finder.class"]
|
28
|
+
entity = options[:"finder.entity"]
|
29
|
+
action = options[:"finder.action"]
|
30
|
+
action = :all unless %i[all single].include?(action)
|
35
31
|
|
36
|
-
|
37
|
-
|
38
|
-
end
|
32
|
+
send("#{action}!", finder_class, entity, params, options[:"finder.action"])
|
33
|
+
end
|
39
34
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
finder_class.new(params: params)
|
44
|
-
else
|
45
|
-
finder_class.new(entity: entity, params: params).result.first
|
35
|
+
private
|
36
|
+
|
37
|
+
def all!(finder_class, entity, params, *)
|
38
|
+
finder_class.new(entity: entity, params: params)
|
46
39
|
end
|
47
|
-
end
|
48
40
|
|
49
|
-
|
50
|
-
|
41
|
+
def single!(finder_class, entity, params, *)
|
42
|
+
apply_id(params)
|
43
|
+
if entity.nil?
|
44
|
+
finder_class.new(params: params).result.first
|
45
|
+
else
|
46
|
+
finder_class.new(entity: entity, params: params).result.first
|
47
|
+
end
|
48
|
+
end
|
51
49
|
|
52
|
-
|
50
|
+
def apply_id(params)
|
51
|
+
return if params[:id].nil?
|
52
|
+
|
53
|
+
params[:id_eq] = params[:id]
|
54
|
+
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.91.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2024-01-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: dry-types
|
@@ -31,9 +31,6 @@ dependencies:
|
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: 0.10.0
|
36
|
-
- - "<"
|
37
34
|
- !ruby/object:Gem::Version
|
38
35
|
version: 0.13.0
|
39
36
|
type: :runtime
|
@@ -41,9 +38,6 @@ dependencies:
|
|
41
38
|
version_requirements: !ruby/object:Gem::Requirement
|
42
39
|
requirements:
|
43
40
|
- - ">="
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 0.10.0
|
46
|
-
- - "<"
|
47
41
|
- !ruby/object:Gem::Version
|
48
42
|
version: 0.13.0
|
49
43
|
- !ruby/object:Gem::Dependency
|
@@ -117,21 +111,7 @@ dependencies:
|
|
117
111
|
- !ruby/object:Gem::Version
|
118
112
|
version: '0'
|
119
113
|
- !ruby/object:Gem::Dependency
|
120
|
-
name:
|
121
|
-
requirement: !ruby/object:Gem::Requirement
|
122
|
-
requirements:
|
123
|
-
- - "~>"
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '3.5'
|
126
|
-
type: :development
|
127
|
-
prerelease: false
|
128
|
-
version_requirements: !ruby/object:Gem::Requirement
|
129
|
-
requirements:
|
130
|
-
- - "~>"
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
version: '3.5'
|
133
|
-
- !ruby/object:Gem::Dependency
|
134
|
-
name: rspec_junit_formatter
|
114
|
+
name: maxitest
|
135
115
|
requirement: !ruby/object:Gem::Requirement
|
136
116
|
requirements:
|
137
117
|
- - ">="
|
@@ -145,21 +125,7 @@ dependencies:
|
|
145
125
|
- !ruby/object:Gem::Version
|
146
126
|
version: '0'
|
147
127
|
- !ruby/object:Gem::Dependency
|
148
|
-
name:
|
149
|
-
requirement: !ruby/object:Gem::Requirement
|
150
|
-
requirements:
|
151
|
-
- - "~>"
|
152
|
-
- !ruby/object:Gem::Version
|
153
|
-
version: '3.5'
|
154
|
-
type: :development
|
155
|
-
prerelease: false
|
156
|
-
version_requirements: !ruby/object:Gem::Requirement
|
157
|
-
requirements:
|
158
|
-
- - "~>"
|
159
|
-
- !ruby/object:Gem::Version
|
160
|
-
version: '3.5'
|
161
|
-
- !ruby/object:Gem::Dependency
|
162
|
-
name: rubocop
|
128
|
+
name: sequel
|
163
129
|
requirement: !ruby/object:Gem::Requirement
|
164
130
|
requirements:
|
165
131
|
- - ">="
|
@@ -173,7 +139,7 @@ dependencies:
|
|
173
139
|
- !ruby/object:Gem::Version
|
174
140
|
version: '0'
|
175
141
|
- !ruby/object:Gem::Dependency
|
176
|
-
name:
|
142
|
+
name: simplecov
|
177
143
|
requirement: !ruby/object:Gem::Requirement
|
178
144
|
requirements:
|
179
145
|
- - ">="
|
@@ -187,21 +153,21 @@ dependencies:
|
|
187
153
|
- !ruby/object:Gem::Version
|
188
154
|
version: '0'
|
189
155
|
- !ruby/object:Gem::Dependency
|
190
|
-
name:
|
156
|
+
name: trailblazer
|
191
157
|
requirement: !ruby/object:Gem::Requirement
|
192
158
|
requirements:
|
193
|
-
- - "
|
159
|
+
- - "~>"
|
194
160
|
- !ruby/object:Gem::Version
|
195
|
-
version:
|
161
|
+
version: 2.1.0
|
196
162
|
type: :development
|
197
163
|
prerelease: false
|
198
164
|
version_requirements: !ruby/object:Gem::Requirement
|
199
165
|
requirements:
|
200
|
-
- - "
|
166
|
+
- - "~>"
|
201
167
|
- !ruby/object:Gem::Version
|
202
|
-
version:
|
168
|
+
version: 2.1.0
|
203
169
|
- !ruby/object:Gem::Dependency
|
204
|
-
name:
|
170
|
+
name: trailblazer-developer
|
205
171
|
requirement: !ruby/object:Gem::Requirement
|
206
172
|
requirements:
|
207
173
|
- - ">="
|
@@ -215,21 +181,7 @@ dependencies:
|
|
215
181
|
- !ruby/object:Gem::Version
|
216
182
|
version: '0'
|
217
183
|
- !ruby/object:Gem::Dependency
|
218
|
-
name:
|
219
|
-
requirement: !ruby/object:Gem::Requirement
|
220
|
-
requirements:
|
221
|
-
- - "~>"
|
222
|
-
- !ruby/object:Gem::Version
|
223
|
-
version: 2.1.0
|
224
|
-
type: :development
|
225
|
-
prerelease: false
|
226
|
-
version_requirements: !ruby/object:Gem::Requirement
|
227
|
-
requirements:
|
228
|
-
- - "~>"
|
229
|
-
- !ruby/object:Gem::Version
|
230
|
-
version: 2.1.0
|
231
|
-
- !ruby/object:Gem::Dependency
|
232
|
-
name: trailblazer-developer
|
184
|
+
name: will_paginate
|
233
185
|
requirement: !ruby/object:Gem::Requirement
|
234
186
|
requirements:
|
235
187
|
- - ">="
|
@@ -243,7 +195,7 @@ dependencies:
|
|
243
195
|
- !ruby/object:Gem::Version
|
244
196
|
version: '0'
|
245
197
|
- !ruby/object:Gem::Dependency
|
246
|
-
name:
|
198
|
+
name: minitest-trailblazer
|
247
199
|
requirement: !ruby/object:Gem::Requirement
|
248
200
|
requirements:
|
249
201
|
- - ">="
|
@@ -304,11 +256,11 @@ files:
|
|
304
256
|
- lib/trailblazer/finder/utils/string.rb
|
305
257
|
- lib/trailblazer/finder/version.rb
|
306
258
|
- lib/trailblazer/operation/finder.rb
|
307
|
-
|
308
|
-
homepage: http://trailblazer.to
|
259
|
+
homepage: https://trailblazer.to
|
309
260
|
licenses:
|
310
261
|
- LGPL-3.0
|
311
|
-
metadata:
|
262
|
+
metadata:
|
263
|
+
rubygems_mfa_required: 'true'
|
312
264
|
post_install_message:
|
313
265
|
rdoc_options: []
|
314
266
|
require_paths:
|
@@ -324,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
324
276
|
- !ruby/object:Gem::Version
|
325
277
|
version: '0'
|
326
278
|
requirements: []
|
327
|
-
rubygems_version: 3.
|
279
|
+
rubygems_version: 3.4.22
|
328
280
|
signing_key:
|
329
281
|
specification_version: 4
|
330
282
|
summary: Trailblazer based finder objects. It is designed to be used on its own as
|
data/trailblazer-finder.gemspec
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path("lib", __dir__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require "trailblazer/finder/version"
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = "trailblazer-finder"
|
9
|
-
spec.version = Trailblazer::Finder::VERSION
|
10
|
-
spec.description = "Trailblazer Finder Objects"
|
11
|
-
spec.summary = "Trailblazer based finder objects. It is designed to be used on its own as a separate gem. It was influenced by popular Ransack gem, but in addition to ActiveRecord, it can be used with Sequel, Hash objects, and RomRB."
|
12
|
-
spec.authors = ["Nick Sutterer", "Marc Tich", "Abdelkader Boudih"]
|
13
|
-
spec.email = %w[apotonick@gmail.com marc@mudsu.com terminale@gmail.com]
|
14
|
-
spec.homepage = "http://trailblazer.to"
|
15
|
-
spec.license = "LGPL-3.0"
|
16
|
-
spec.files = Dir.glob("lib/**/*")
|
17
|
-
spec.files << ['trailblazer-finder.gemspec']
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_dependency "dry-types", ">= 1.0.0"
|
22
|
-
spec.add_dependency "trailblazer-activity", ">= 0.10.0", "< 0.13.0"
|
23
|
-
|
24
|
-
spec.add_development_dependency "activerecord"
|
25
|
-
spec.add_development_dependency "bundler"
|
26
|
-
spec.add_development_dependency "kaminari"
|
27
|
-
spec.add_development_dependency "kaminari-activerecord"
|
28
|
-
spec.add_development_dependency "rake"
|
29
|
-
spec.add_development_dependency "rspec", "~> 3.5"
|
30
|
-
spec.add_development_dependency "rspec_junit_formatter"
|
31
|
-
spec.add_development_dependency "rspec-mocks", "~> 3.5"
|
32
|
-
spec.add_development_dependency "rubocop"
|
33
|
-
spec.add_development_dependency "rubocop-rspec"
|
34
|
-
spec.add_development_dependency "sequel"
|
35
|
-
spec.add_development_dependency "simplecov"
|
36
|
-
spec.add_development_dependency "trailblazer", "~> 2.1.0"
|
37
|
-
spec.add_development_dependency "trailblazer-developer"
|
38
|
-
spec.add_development_dependency "will_paginate"
|
39
|
-
|
40
|
-
spec.required_ruby_version = ">= 2.5.0"
|
41
|
-
end
|