trailblazer-finder 0.10.3 → 0.50.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +3 -0
- data/README.md +4 -4
- data/lib/trailblazer/finder/activities/find.rb +0 -1
- data/lib/trailblazer/finder/activities/prepare.rb +2 -3
- data/lib/trailblazer/finder/activities/prepare_adapter.rb +26 -0
- data/lib/trailblazer/finder/activities/process.rb +0 -1
- data/lib/trailblazer/finder/activities/process_adapters.rb +19 -23
- data/lib/trailblazer/finder/adapters/kaminari/paging.rb +1 -2
- data/lib/trailblazer/finder/adapters/will_paginate/paging.rb +1 -2
- data/lib/trailblazer/finder/dsl.rb +6 -4
- data/lib/trailblazer/finder/version.rb +1 -1
- data/spec/trailblazer/finder/adapters/active_record_spec.rb +1 -1
- data/spec/trailblazer/finder/adapters/kaminari_spec.rb +13 -8
- data/spec/trailblazer/finder/adapters/sequel_spec.rb +1 -1
- data/spec/trailblazer/finder/adapters/will_paginate_spec.rb +12 -7
- data/spec/trailblazer/finder/dsl_spec.rb +4 -13
- data/spec/trailblazer/operation/finder_spec.rb +2 -2
- metadata +3 -4
- data/.rubocop_todo.yml +0 -78
- data/lib/trailblazer/finder/activities/prepare_adapters.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfcac8d017065a8faea558faebaa1bd9e742b7ceb9444a50eafd79d2c759bbfc
|
4
|
+
data.tar.gz: fdfafe463cba185afb34934f981b3428bb357a4031f941e22cb44e1c45608e11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89c313cc891e5ef6b1d6e07145e23541d74698b543e47f4213d621e21925ec18c60d01d66cdbc2c6fe9d2ddbbfc4d5ef201f1bb80a1264ffe70c01f3e37772e0
|
7
|
+
data.tar.gz: 2a00366ecc9c10ae045ce1d1c69f455cc7a8b101be8bb360228cf8cb148833502ea6039ce30740781bd93f97c8cabf878a6129beeb072c9e4e6e0b13b5c3128f
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -78,7 +78,7 @@ Basically for most use cases, Entity is the entity/model/array of hashes you wis
|
|
78
78
|
```ruby
|
79
79
|
class Post::Finder < Trailblazer::Finder
|
80
80
|
# Without defining an ORM everything defaults to dealing with hash objects
|
81
|
-
|
81
|
+
adapter :ActiveRecord
|
82
82
|
|
83
83
|
# Optional if you use it as option in the caller, Model/Entity or Array with Hashes
|
84
84
|
entity { Post }
|
@@ -364,7 +364,7 @@ You can specify the adapters you wish to use inside your enherited Finder class.
|
|
364
364
|
### Adapters Example
|
365
365
|
```ruby
|
366
366
|
class Post::Finder < Trailblazer::Finder
|
367
|
-
|
367
|
+
adapter "ActiveRecord"
|
368
368
|
end
|
369
369
|
```
|
370
370
|
|
@@ -374,7 +374,7 @@ The only thing the [ActiveRecord](https://github.com/rails/rails/tree/master/act
|
|
374
374
|
#### Active Record Example
|
375
375
|
```ruby
|
376
376
|
class Post::Finder < Trailblazer::Finder
|
377
|
-
|
377
|
+
adapter "ActiveRecord"
|
378
378
|
end
|
379
379
|
```
|
380
380
|
|
@@ -384,7 +384,7 @@ The only thing the [Sequel](https://github.com/jeremyevans/sequel) adapter does,
|
|
384
384
|
#### Sequel Example
|
385
385
|
```ruby
|
386
386
|
class Post::Finder < Trailblazer::Finder
|
387
|
-
|
387
|
+
adapter "Sequel"
|
388
388
|
end
|
389
389
|
```
|
390
390
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "
|
3
|
+
require_relative "prepare_adapter"
|
4
4
|
require_relative "prepare_entity"
|
5
5
|
require_relative "prepare_properties"
|
6
6
|
require_relative "prepare_filters"
|
@@ -11,14 +11,13 @@ require_relative "prepare_sorting"
|
|
11
11
|
module Trailblazer
|
12
12
|
class Finder
|
13
13
|
module Activities
|
14
|
-
# Prepare Activity
|
15
14
|
class Prepare < Trailblazer::Activity::Railway
|
16
15
|
def clean_ctx((ctx, flow_options), **)
|
17
16
|
ctx.delete(:options)
|
18
17
|
[Activity::Right, [ctx, flow_options]]
|
19
18
|
end
|
20
19
|
|
21
|
-
step Subprocess(
|
20
|
+
step Subprocess(PrepareAdapter)
|
22
21
|
step Subprocess(PrepareEntity)
|
23
22
|
step Subprocess(PrepareProperties)
|
24
23
|
step Subprocess(PrepareFilters)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Trailblazer
|
4
|
+
class Finder
|
5
|
+
module Activities
|
6
|
+
class PrepareAdapter < Trailblazer::Activity::Railway
|
7
|
+
|
8
|
+
def set_adapter(ctx, **)
|
9
|
+
ctx[:adapter] = ctx.dig(:config, :adapter) || "Basic"
|
10
|
+
end
|
11
|
+
|
12
|
+
def validate_adapter(_ctx, adapter:, **)
|
13
|
+
(ORM_ADAPTERS + ["Basic"]).include? adapter.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def is_invalid?((ctx, _flow_options), **_circuit_options)
|
17
|
+
(ctx[:errors] ||= []) << {adapter: "The specified adapter are invalid"}
|
18
|
+
end
|
19
|
+
|
20
|
+
step :set_adapter
|
21
|
+
step :validate_adapter
|
22
|
+
fail :is_invalid?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -4,36 +4,32 @@ module Trailblazer
|
|
4
4
|
class Finder
|
5
5
|
module Activities
|
6
6
|
class ProcessAdapters < Trailblazer::Activity::Railway
|
7
|
-
def
|
8
|
-
ctx[:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
ctx[:orm][:sorting] = "Trailblazer::Finder::Adapters::#{adapter}::Sorting"
|
16
|
-
return true
|
17
|
-
end
|
7
|
+
def set_adapter((ctx, flow_options), **)
|
8
|
+
adapter = ctx[:adapter]
|
9
|
+
ctx[:orm] = {}
|
10
|
+
ctx[:orm][:adapter] = adapter
|
11
|
+
ctx[:orm][:predicates] = "Trailblazer::Finder::Adapters::#{adapter}::Predicates"
|
12
|
+
ctx[:orm][:paging] = "Trailblazer::Finder::Adapters::#{adapter}::Paging"
|
13
|
+
ctx[:orm][:sorting] = "Trailblazer::Finder::Adapters::#{adapter}::Sorting"
|
14
|
+
true
|
18
15
|
end
|
19
16
|
|
20
|
-
def
|
21
|
-
ctx
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
17
|
+
def set_paginator(ctx, **)
|
18
|
+
paginator = ctx.dig(:config, :paginator)
|
19
|
+
return true unless paginator
|
20
|
+
return false unless ORM_ADAPTERS.include?(ctx[:orm][:adapter])
|
21
|
+
return false unless PAGING_ADAPTERS.include?(paginator)
|
22
|
+
ctx[:orm][:paging] = "Trailblazer::Finder::Adapters::#{paginator}::Paging"
|
27
23
|
true
|
28
24
|
end
|
29
25
|
|
30
|
-
def
|
31
|
-
(ctx[:errors] ||= []) << {
|
26
|
+
def invalid_paginator_error(ctx, **)
|
27
|
+
(ctx[:errors] ||= []) << {paginator: "Can't use paginator #{ctx.dig(:config, :paginator)} without using an ORM like ActiveRecord or Sequel"}
|
32
28
|
end
|
33
29
|
|
34
|
-
step :
|
35
|
-
step :
|
36
|
-
fail :
|
30
|
+
step :set_adapter, fast_track: true
|
31
|
+
step :set_paginator
|
32
|
+
fail :invalid_paginator_error
|
37
33
|
end
|
38
34
|
end
|
39
35
|
end
|
@@ -33,10 +33,12 @@ module Trailblazer
|
|
33
33
|
config[:filters][filter_name][:block] = block || nil
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def adapter(adapter)
|
37
|
+
config[:adapter] = adapter.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
def paginator(paginator)
|
41
|
+
config[:paginator] = paginator.to_s
|
40
42
|
end
|
41
43
|
|
42
44
|
def apply_config(options, **)
|
@@ -32,15 +32,15 @@ module Trailblazer
|
|
32
32
|
finder_class(&block).new params: filter
|
33
33
|
end
|
34
34
|
|
35
|
-
describe "#
|
35
|
+
describe "#adapter" do
|
36
36
|
it "cannot use kaminari without an actual orm" do
|
37
37
|
10.times { |i| Product.create name: "product_#{i}" }
|
38
38
|
finder = new_finder do
|
39
|
-
|
39
|
+
paginator :Kaminari
|
40
40
|
paging per_page: 2, min_per_page: 1, max_per_page: 5
|
41
41
|
end
|
42
42
|
|
43
|
-
expect(finder.errors).to eq [{
|
43
|
+
expect(finder.errors).to eq [{paginator: "Can't use paginator Kaminari without using an ORM like ActiveRecord or Sequel"}]
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -48,7 +48,8 @@ module Trailblazer
|
|
48
48
|
it "sets the paging values and shows only the first page results" do
|
49
49
|
10.times { |i| Product.create name: "product_#{i}" }
|
50
50
|
finder = new_finder do
|
51
|
-
|
51
|
+
adapter :ActiveRecord
|
52
|
+
paginator "Kaminari"
|
52
53
|
paging per_page: 2, min_per_page: 1, max_per_page: 5
|
53
54
|
end
|
54
55
|
|
@@ -58,7 +59,8 @@ module Trailblazer
|
|
58
59
|
it "accepts per_page as a parameter" do
|
59
60
|
10.times { |i| Product.create name: "product_#{i}" }
|
60
61
|
finder = new_finder page: 2, per_page: 4 do
|
61
|
-
|
62
|
+
adapter "ActiveRecord"
|
63
|
+
paginator "Kaminari"
|
62
64
|
paging per_page: 5, min_per_page: 2, max_per_page: 8
|
63
65
|
end
|
64
66
|
|
@@ -69,7 +71,8 @@ module Trailblazer
|
|
69
71
|
it "uses max_per_page in finder as maximum per_page" do
|
70
72
|
10.times { |i| Product.create name: "product_#{i}" }
|
71
73
|
finder = new_finder page: 2, per_page: 9 do
|
72
|
-
|
74
|
+
adapter "ActiveRecord"
|
75
|
+
paginator "Kaminari"
|
73
76
|
paging per_page: 5, min_per_page: 2, max_per_page: 8
|
74
77
|
end
|
75
78
|
|
@@ -80,7 +83,8 @@ module Trailblazer
|
|
80
83
|
it "uses min_per_page in finder as minimum per_page" do
|
81
84
|
10.times { |i| Product.create name: "product_#{i}" }
|
82
85
|
finder = new_finder page: 2, per_page: 1 do
|
83
|
-
|
86
|
+
adapter "ActiveRecord"
|
87
|
+
paginator "Kaminari"
|
84
88
|
paging per_page: 5, min_per_page: 2, max_per_page: 8
|
85
89
|
end
|
86
90
|
|
@@ -94,7 +98,8 @@ module Trailblazer
|
|
94
98
|
5.times { |i| Product.create name: "product_#{i}" }
|
95
99
|
5.times { |_i| Product.create name: "product" }
|
96
100
|
finder = new_finder name_eq: "product", sort: "id desc", page: 2 do
|
97
|
-
|
101
|
+
adapter "ActiveRecord"
|
102
|
+
paginator "Kaminari"
|
98
103
|
paging per_page: 2, min_per_page: 1, max_per_page: 5
|
99
104
|
property :name, type: Types::String
|
100
105
|
property :id, type: Types::Integer, sortable: true
|
@@ -38,11 +38,11 @@ module Trailblazer
|
|
38
38
|
it "cannot use kaminari without an actual orm" do
|
39
39
|
10.times { |i| Product.create name: "product_#{i}" }
|
40
40
|
finder = new_finder do
|
41
|
-
|
41
|
+
paginator "WillPaginate"
|
42
42
|
paging per_page: 2, min_per_page: 1, max_per_page: 5
|
43
43
|
end
|
44
44
|
|
45
|
-
expect(finder.errors).to eq [{
|
45
|
+
expect(finder.errors).to eq [{paginator: "Can't use paginator WillPaginate without using an ORM like ActiveRecord or Sequel"}]
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -50,7 +50,8 @@ module Trailblazer
|
|
50
50
|
it "sets the paging values and shows only the first page results" do
|
51
51
|
10.times { |i| Product.create name: "product_#{i}" }
|
52
52
|
finder = new_finder do
|
53
|
-
|
53
|
+
adapter "ActiveRecord"
|
54
|
+
paginator "WillPaginate"
|
54
55
|
paging per_page: 2, min_per_page: 1, max_per_page: 5
|
55
56
|
end
|
56
57
|
|
@@ -60,7 +61,8 @@ module Trailblazer
|
|
60
61
|
it "accepts per_page as a parameter" do
|
61
62
|
10.times { |i| Product.create name: "product_#{i}" }
|
62
63
|
finder = new_finder page: 2, per_page: 4 do
|
63
|
-
|
64
|
+
adapter "ActiveRecord"
|
65
|
+
paginator "WillPaginate"
|
64
66
|
paging per_page: 5, min_per_page: 2, max_per_page: 8
|
65
67
|
end
|
66
68
|
|
@@ -71,7 +73,8 @@ module Trailblazer
|
|
71
73
|
it "uses max_per_page in finder as maximum per_page" do
|
72
74
|
10.times { |i| Product.create name: "product_#{i}" }
|
73
75
|
finder = new_finder page: 2, per_page: 9 do
|
74
|
-
|
76
|
+
adapter "ActiveRecord"
|
77
|
+
paginator "WillPaginate"
|
75
78
|
paging per_page: 5, min_per_page: 2, max_per_page: 8
|
76
79
|
end
|
77
80
|
|
@@ -82,7 +85,8 @@ module Trailblazer
|
|
82
85
|
it "uses min_per_page in finder as minimum per_page" do
|
83
86
|
10.times { |i| Product.create name: "product_#{i}" }
|
84
87
|
finder = new_finder page: 2, per_page: 1 do
|
85
|
-
|
88
|
+
adapter "ActiveRecord"
|
89
|
+
paginator "WillPaginate"
|
86
90
|
paging per_page: 5, min_per_page: 2, max_per_page: 8
|
87
91
|
end
|
88
92
|
|
@@ -96,7 +100,8 @@ module Trailblazer
|
|
96
100
|
5.times { |i| Product.create name: "product_#{i}" }
|
97
101
|
5.times { |_i| Product.create name: "product" }
|
98
102
|
finder = new_finder name_eq: "product", sort: "id desc", page: 2 do
|
99
|
-
|
103
|
+
adapter "ActiveRecord"
|
104
|
+
paginator "WillPaginate"
|
100
105
|
paging per_page: 2, min_per_page: 1, max_per_page: 5
|
101
106
|
property :name, type: Types::String
|
102
107
|
property :id, type: Types::Integer, sortable: true
|
@@ -60,29 +60,20 @@ module Trailblazer
|
|
60
60
|
it "checks for a valid adapter and returns an error" do
|
61
61
|
entity = [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}]
|
62
62
|
finder = new_finder entity, value_eq: "Test 1" do
|
63
|
-
|
63
|
+
adapter :NonExisting
|
64
64
|
end
|
65
65
|
|
66
|
-
expect(finder.errors).to eq [{
|
67
|
-
end
|
68
|
-
|
69
|
-
it "checks if multiple orm adapters are requested and returns an error" do
|
70
|
-
entity = [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}]
|
71
|
-
finder = new_finder entity, value_eq: "Test 1" do
|
72
|
-
adapters :ActiveRecord, :Sequel
|
73
|
-
end
|
74
|
-
|
75
|
-
expect(finder.errors).to eq [{adapters: "More then one ORM adapter specified"}]
|
66
|
+
expect(finder.errors).to eq [{adapter: "The specified adapter are invalid"}]
|
76
67
|
end
|
77
68
|
|
78
69
|
it "sets the adapter in the config" do
|
79
70
|
entity = [{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}]
|
80
71
|
finder = new_finder entity, value_eq: "Test 1" do
|
81
|
-
|
72
|
+
adapter "ActiveRecord"
|
82
73
|
property :value, type: Base
|
83
74
|
end
|
84
75
|
|
85
|
-
expect(finder.class.config[:
|
76
|
+
expect(finder.class.config[:adapter]).to eq "ActiveRecord"
|
86
77
|
end
|
87
78
|
end
|
88
79
|
|
@@ -5,7 +5,7 @@ require "trailblazer"
|
|
5
5
|
require "spec_helper_active_record"
|
6
6
|
|
7
7
|
class Product::FinderNoEntity < Trailblazer::Finder
|
8
|
-
|
8
|
+
adapter "ActiveRecord"
|
9
9
|
|
10
10
|
property :id, type: Types::Integer
|
11
11
|
property :name, type: Types::String, sortable: true
|
@@ -19,7 +19,7 @@ class Product::FinderNoEntity < Trailblazer::Finder
|
|
19
19
|
end
|
20
20
|
|
21
21
|
class Product::FinderWithEntity < Trailblazer::Finder
|
22
|
-
|
22
|
+
adapter "ActiveRecord"
|
23
23
|
|
24
24
|
entity { Product }
|
25
25
|
|
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.50.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: 2020-03-
|
13
|
+
date: 2020-03-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: dry-types
|
@@ -275,7 +275,6 @@ extra_rdoc_files: []
|
|
275
275
|
files:
|
276
276
|
- ".gitignore"
|
277
277
|
- ".rubocop.yml"
|
278
|
-
- ".rubocop_todo.yml"
|
279
278
|
- ".travis.yml"
|
280
279
|
- CHANGES.md
|
281
280
|
- Gemfile
|
@@ -285,7 +284,7 @@ files:
|
|
285
284
|
- lib/trailblazer/finder.rb
|
286
285
|
- lib/trailblazer/finder/activities/find.rb
|
287
286
|
- lib/trailblazer/finder/activities/prepare.rb
|
288
|
-
- lib/trailblazer/finder/activities/
|
287
|
+
- lib/trailblazer/finder/activities/prepare_adapter.rb
|
289
288
|
- lib/trailblazer/finder/activities/prepare_entity.rb
|
290
289
|
- lib/trailblazer/finder/activities/prepare_filters.rb
|
291
290
|
- lib/trailblazer/finder/activities/prepare_paging.rb
|
data/.rubocop_todo.yml
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
# This configuration was generated by
|
2
|
-
# `rubocop --auto-gen-config`
|
3
|
-
# on 2018-08-23 00:10:15 +0200 using RuboCop version 0.58.2.
|
4
|
-
# The point is for the user to remove these configuration records
|
5
|
-
# one by one as the offenses are removed from the code base.
|
6
|
-
# Note that changes in the inspected code, or installation of new
|
7
|
-
# versions of RuboCop, may require this file to be generated again.
|
8
|
-
|
9
|
-
# Offense count: 1
|
10
|
-
Metrics/AbcSize:
|
11
|
-
Max: 31
|
12
|
-
|
13
|
-
# Offense count: 2
|
14
|
-
Metrics/CyclomaticComplexity:
|
15
|
-
Max: 7
|
16
|
-
|
17
|
-
# Offense count: 13
|
18
|
-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
19
|
-
# URISchemes: http, https
|
20
|
-
Metrics/LineLength:
|
21
|
-
Max: 283
|
22
|
-
|
23
|
-
# Offense count: 1
|
24
|
-
# Configuration parameters: CountKeywordArgs.
|
25
|
-
Metrics/ParameterLists:
|
26
|
-
Max: 6
|
27
|
-
|
28
|
-
# Offense count: 1
|
29
|
-
RSpec/DescribeClass:
|
30
|
-
Exclude:
|
31
|
-
- 'spec/trailblazer/operation/finder_spec.rb'
|
32
|
-
|
33
|
-
# Offense count: 78
|
34
|
-
# Configuration parameters: Max.
|
35
|
-
RSpec/ExampleLength:
|
36
|
-
Exclude:
|
37
|
-
- 'spec/trailblazer/finder/adapters/active_record_spec.rb'
|
38
|
-
- 'spec/trailblazer/finder/adapters/basic_spec.rb'
|
39
|
-
- 'spec/trailblazer/finder/adapters/kaminari_spec.rb'
|
40
|
-
- 'spec/trailblazer/finder/adapters/sequel_spec.rb'
|
41
|
-
- 'spec/trailblazer/finder/adapters/will_paginate_spec.rb'
|
42
|
-
- 'spec/trailblazer/finder/base_spec.rb'
|
43
|
-
- 'spec/trailblazer/finder/dsl_spec.rb'
|
44
|
-
- 'spec/trailblazer/finder/utils/string_spec.rb'
|
45
|
-
|
46
|
-
# Offense count: 62
|
47
|
-
# Configuration parameters: AggregateFailuresByDefault.
|
48
|
-
RSpec/MultipleExpectations:
|
49
|
-
Max: 7
|
50
|
-
|
51
|
-
# Offense count: 2
|
52
|
-
RSpec/RepeatedDescription:
|
53
|
-
Exclude:
|
54
|
-
- 'spec/trailblazer/finder/adapters/basic_spec.rb'
|
55
|
-
|
56
|
-
# Offense count: 6
|
57
|
-
# Cop supports --auto-correct.
|
58
|
-
# Configuration parameters: AutoCorrect, EnforcedStyle.
|
59
|
-
# SupportedStyles: nested, compact
|
60
|
-
Style/ClassAndModuleChildren:
|
61
|
-
Exclude:
|
62
|
-
- 'spec/trailblazer/operation/finder_spec.rb'
|
63
|
-
|
64
|
-
# Offense count: 1
|
65
|
-
# Configuration parameters: SuspiciousParamNames.
|
66
|
-
# SuspiciousParamNames: options, opts, args, params, parameters
|
67
|
-
Style/OptionHash:
|
68
|
-
Exclude:
|
69
|
-
- 'lib/trailblazer/finder/dsl.rb'
|
70
|
-
|
71
|
-
# Offense count: 3
|
72
|
-
Style/Send:
|
73
|
-
Exclude:
|
74
|
-
- 'lib/trailblazer/finder/adapters/sequel/sorting.rb'
|
75
|
-
- 'lib/trailblazer/operation/finder.rb'
|
76
|
-
|
77
|
-
RSpec/DescribedClass:
|
78
|
-
SkipBlocks: true
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Trailblazer
|
4
|
-
class Finder
|
5
|
-
module Activities
|
6
|
-
# Adapters Activity
|
7
|
-
class PrepareAdapters < Trailblazer::Activity::Railway
|
8
|
-
def check_for_adapters(ctx, **)
|
9
|
-
adapters = ctx.dig(:config, :adapters)
|
10
|
-
return true if adapters.empty?
|
11
|
-
|
12
|
-
adapters.each do |adapter|
|
13
|
-
return true if Finder::Adapters.constants.include?(adapter.to_sym)
|
14
|
-
end
|
15
|
-
false
|
16
|
-
end
|
17
|
-
|
18
|
-
## Only one ORM can be accepted
|
19
|
-
def validate_adapters(ctx, **)
|
20
|
-
adapters = ctx.dig(:config, :adapters)
|
21
|
-
return true if adapters.empty?
|
22
|
-
|
23
|
-
adapters.each do |adapter|
|
24
|
-
if ORM_ADAPTERS.include?(adapter)
|
25
|
-
return false if (adapters & (ORM_ADAPTERS - [adapter])).any?
|
26
|
-
end
|
27
|
-
end
|
28
|
-
true
|
29
|
-
end
|
30
|
-
|
31
|
-
def invalid_adapters_error((ctx, flow_options), **_circuit_options)
|
32
|
-
(ctx[:errors] ||= []) << {adapters: "One or more of the specified adapters are invalid"}
|
33
|
-
end
|
34
|
-
|
35
|
-
def multiple_orm_error((ctx, flow_options), **_circuit_options)
|
36
|
-
(ctx[:errors] ||= []) << {adapters: "More then one ORM adapter specified"}
|
37
|
-
end
|
38
|
-
|
39
|
-
def set_adapters(ctx, **)
|
40
|
-
adapters = ctx.dig(:config, :adapters)
|
41
|
-
ctx[:adapters] = (ORM_ADAPTERS & adapters).any? ? adapters : ["Basic"] + adapters
|
42
|
-
end
|
43
|
-
|
44
|
-
step :check_for_adapters
|
45
|
-
fail :invalid_adapters_error, Output(:success) => End(:failure)
|
46
|
-
step :validate_adapters
|
47
|
-
fail :multiple_orm_error
|
48
|
-
step :set_adapters
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|