trailblazer-finder 0.10.2 → 0.10.3
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/lib/trailblazer/finder/activities/find.rb +4 -4
- data/lib/trailblazer/finder/activities/prepare_entity.rb +3 -3
- data/lib/trailblazer/finder/activities/prepare_paging.rb +3 -9
- data/lib/trailblazer/finder/activities/prepare_params.rb +3 -3
- data/lib/trailblazer/finder/activities/prepare_sorting.rb +3 -8
- data/lib/trailblazer/finder/dsl.rb +5 -4
- data/lib/trailblazer/finder/version.rb +1 -1
- data/spec/trailblazer/operation/finder_spec.rb +9 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1878b1acf62f66eb1c410b476037ab0c0aa45b761805f151fe987f6d81b24ecc
|
4
|
+
data.tar.gz: 27e69700c5507481a8c06828889d451c98976c92a1b8542602565ecf438461e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe66baf784a25237ee917eee6c261af6dba12e4f5e63df164a1cc37d268fad4b893c315594c2aea9d4083fc20ab3fedab50baf52a447dc198ea19ae0b260cc38
|
7
|
+
data.tar.gz: 50051b6a1e6a8413c1d4d70d455310fa2f4114e598737c0334fe1f1a0124906227c77f42d01e4722e76b352fc6ca55af1beef90f50309bf2d8ffd8690e034f4a
|
data/CHANGES.md
CHANGED
@@ -11,13 +11,13 @@ module Trailblazer
|
|
11
11
|
def process_params(ctx, params:, **)
|
12
12
|
params.each do |attribute, value|
|
13
13
|
result = {}
|
14
|
-
|
15
|
-
fetch_filters(ctx, result,
|
16
|
-
fetch_properties(result,
|
14
|
+
filter_attribute = attribute.to_sym
|
15
|
+
fetch_filters(ctx, result, filter_attribute) || result if ctx[:filters].include?(filter_attribute)
|
16
|
+
fetch_properties(result, filter_attribute, value, ctx[:properties]) || result
|
17
17
|
next ctx[:params].delete(attribute) if result.empty?
|
18
18
|
|
19
19
|
ctx[:process] ||= {}
|
20
|
-
ctx[:process][
|
20
|
+
ctx[:process][filter_attribute] = result.merge!(value: value)
|
21
21
|
end
|
22
22
|
true
|
23
23
|
end
|
@@ -16,9 +16,9 @@ module Trailblazer
|
|
16
16
|
ctx[:entity] = ctx.dig(:options,:entity) || instance_eval(&ctx[:config][:entity])
|
17
17
|
end
|
18
18
|
|
19
|
-
step
|
20
|
-
fail
|
21
|
-
step
|
19
|
+
step :validate_entity
|
20
|
+
fail :invalid_entity_error
|
21
|
+
step :set_entity
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -27,15 +27,9 @@ module Trailblazer
|
|
27
27
|
true
|
28
28
|
end
|
29
29
|
|
30
|
-
step (:
|
31
|
-
|
32
|
-
step
|
33
|
-
Output(:success) => Track(:end_paging),
|
34
|
-
Output(:failure) => Track(:failure)
|
35
|
-
step (:clear_paging),
|
36
|
-
magnetic_to: :end_paging,
|
37
|
-
Output(:success) => Track(:success),
|
38
|
-
Output(:failure) => Track(:failure)
|
30
|
+
step :check_paging, Output(:failure) => Track(:end_paging)
|
31
|
+
step :set_paging
|
32
|
+
step :clear_paging, magnetic_to: :end_paging
|
39
33
|
end
|
40
34
|
end
|
41
35
|
end
|
@@ -18,9 +18,9 @@ module Trailblazer
|
|
18
18
|
ctx[:params] = ctx[:options][:params] || {}
|
19
19
|
end
|
20
20
|
|
21
|
-
step
|
22
|
-
fail
|
23
|
-
step
|
21
|
+
step :validate_params
|
22
|
+
fail :invalid_params_error
|
23
|
+
step :set_params
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -37,15 +37,10 @@ module Trailblazer
|
|
37
37
|
true
|
38
38
|
end
|
39
39
|
|
40
|
-
step
|
41
|
-
Output(:success) => Track(:paging),
|
40
|
+
step :check_sorting,
|
42
41
|
Output(:failure) => Track(:end_sorting)
|
43
|
-
step
|
44
|
-
|
45
|
-
Output(:success) => Track(:end_sorting),
|
46
|
-
Output(:failure) => Track(:failure)
|
47
|
-
step (:clear_sorting),
|
48
|
-
magnetic_to: :end_sorting
|
42
|
+
step :set_sorting
|
43
|
+
step :clear_sorting, magnetic_to: :end_sorting
|
49
44
|
end
|
50
45
|
end
|
51
46
|
end
|
@@ -26,10 +26,11 @@ module Trailblazer
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def filter_by(name, options = {}, &block)
|
29
|
-
|
30
|
-
config[:filters][
|
31
|
-
config[:filters][
|
32
|
-
config[:filters][
|
29
|
+
filter_name = name.to_sym
|
30
|
+
config[:filters][filter_name] = {}
|
31
|
+
config[:filters][filter_name][:name] = name
|
32
|
+
config[:filters][filter_name][:with] = options[:with] if options.include?(:with)
|
33
|
+
config[:filters][filter_name][:block] = block || nil
|
33
34
|
end
|
34
35
|
|
35
36
|
def adapters(*adapters)
|
@@ -54,7 +54,7 @@ describe "Trailblazer::Operation - Finder Macro" do
|
|
54
54
|
before do
|
55
55
|
Product.destroy_all
|
56
56
|
Product.reset_pk_sequence
|
57
|
-
|
57
|
+
22.times { |i| Product.create name: "product_#{i}" }
|
58
58
|
end
|
59
59
|
|
60
60
|
after do
|
@@ -91,6 +91,13 @@ describe "Trailblazer::Operation - Finder Macro" do
|
|
91
91
|
expect(result[:finder].result.last.name).to eq "product_19"
|
92
92
|
end
|
93
93
|
|
94
|
+
it "Can find multiple rows by escaped name if key is string" do
|
95
|
+
params = {"escaped_name" => "product_1"}
|
96
|
+
result = Product::Index.call(params: params)
|
97
|
+
|
98
|
+
expect(result[:finder].result.last.name).to eq "product_19"
|
99
|
+
end
|
100
|
+
|
94
101
|
it "Can find a single row by id when no entity type is given in macro" do
|
95
102
|
params = {id: 8}
|
96
103
|
result = Product::ShowNoEntity.call(params: params)
|
@@ -109,6 +116,7 @@ describe "Trailblazer::Operation - Finder Macro" do
|
|
109
116
|
params = {escaped_name: "product_1"}
|
110
117
|
result = Product::IndexNoEntity.call(params: params)
|
111
118
|
|
119
|
+
expect(result[:finder].result.count).to eq 11
|
112
120
|
expect(result[:finder].result.last.name).to eq "product_19"
|
113
121
|
end
|
114
122
|
end
|