trailblazer-finder 0.50.0 → 0.80.1
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/find.rb +16 -16
- data/lib/trailblazer/finder/activities/prepare_adapter.rb +2 -3
- data/lib/trailblazer/finder/activities/prepare_entity.rb +2 -2
- data/lib/trailblazer/finder/activities/prepare_paging.rb +2 -2
- data/lib/trailblazer/finder/activities/prepare_properties.rb +1 -5
- data/lib/trailblazer/finder/activities/process_adapters.rb +8 -2
- data/lib/trailblazer/finder/adapters/active_record/paging.rb +1 -1
- data/lib/trailblazer/finder/adapters/active_record/predicates.rb +14 -14
- data/lib/trailblazer/finder/adapters/active_record/sorting.rb +1 -1
- data/lib/trailblazer/finder/adapters/basic/paging.rb +1 -1
- data/lib/trailblazer/finder/adapters/basic/predicates.rb +14 -14
- data/lib/trailblazer/finder/adapters/basic/sorting.rb +1 -1
- data/lib/trailblazer/finder/adapters/kaminari/paging.rb +1 -1
- data/lib/trailblazer/finder/adapters/sequel/paging.rb +1 -1
- data/lib/trailblazer/finder/adapters/sequel/predicates.rb +14 -14
- data/lib/trailblazer/finder/adapters/sequel/sorting.rb +1 -1
- data/lib/trailblazer/finder/adapters/will_paginate/paging.rb +1 -1
- data/lib/trailblazer/finder/dsl.rb +1 -1
- data/lib/trailblazer/finder/find.rb +2 -1
- data/lib/trailblazer/finder/helpers/sorting.rb +4 -1
- data/lib/trailblazer/finder/version.rb +1 -1
- data/lib/trailblazer/finder.rb +1 -7
- data/lib/trailblazer/operation/finder.rb +2 -2
- data/trailblazer-finder.gemspec +8 -8
- metadata +26 -57
- data/.gitignore +0 -24
- data/.rubocop.yml +0 -5
- data/.travis.yml +0 -7
- data/CHANGES.md +0 -40
- data/Gemfile +0 -14
- data/LICENSE.txt +0 -9
- data/README.md +0 -451
- data/Rakefile +0 -31
- data/spec/spec_helper.rb +0 -14
- data/spec/spec_helper_active_record.rb +0 -48
- data/spec/spec_helper_sequel.rb +0 -33
- data/spec/spec_helper_will_paginate.rb +0 -13
- data/spec/trailblazer/finder/adapters/active_record_spec.rb +0 -267
- data/spec/trailblazer/finder/adapters/basic_spec.rb +0 -251
- data/spec/trailblazer/finder/adapters/kaminari_spec.rb +0 -115
- data/spec/trailblazer/finder/adapters/sequel_spec.rb +0 -267
- data/spec/trailblazer/finder/adapters/will_paginate_spec.rb +0 -117
- data/spec/trailblazer/finder/base_spec.rb +0 -417
- data/spec/trailblazer/finder/dsl_spec.rb +0 -204
- data/spec/trailblazer/finder/utils/hash_spec.rb +0 -26
- data/spec/trailblazer/finder/utils/splitter_spec.rb +0 -39
- data/spec/trailblazer/finder/utils/string_spec.rb +0 -69
- data/spec/trailblazer/operation/finder_spec.rb +0 -122
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9ed5fd3c089acb644a3c240478b2aae6b028f63108a94fba82e3afb9164e226
|
4
|
+
data.tar.gz: 155a516ced78ae4621595ec091e5cf5c651d187949961ddc793b3d57bc10aaf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dec5f359b98b15578b1bc38f521a43200bfe5f68b92daa3e70e2274bfc0a6e43503564dc012f0478af51f3fd2afdb22dc0b8293239c2919508d0ab2158117dfa
|
7
|
+
data.tar.gz: 363bc66d7057c76290622ed083aaa270896ef956ca16019d63d8c653fd95630764fd116f6df052e9061e8c5442eaec0dec6e130c159a92e829c79e37251f01fa
|
@@ -6,8 +6,7 @@ module Trailblazer
|
|
6
6
|
class Find < Trailblazer::Activity::Railway
|
7
7
|
PREDICATES = %w[eq not_eq blank not_blank lt lte gt gte sw not_sw ew not_ew cont not_cont].freeze
|
8
8
|
|
9
|
-
|
10
|
-
def process_params(ctx, params:, **)
|
9
|
+
def process_params(ctx, params:, **)
|
11
10
|
params.each do |attribute, value|
|
12
11
|
result = {}
|
13
12
|
filter_attribute = attribute.to_sym
|
@@ -31,23 +30,24 @@ module Trailblazer
|
|
31
30
|
step :set_finder
|
32
31
|
|
33
32
|
private
|
34
|
-
def fetch_filters(ctx, result, attribute)
|
35
|
-
filter_attribute = ctx[:filters][attribute]
|
36
|
-
result[:filter] = {}
|
37
|
-
result[:name] = attribute
|
38
|
-
result[:filter][:handler] = filter_attribute[:with] || filter_attribute[:block]
|
39
|
-
end
|
40
33
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
34
|
+
def fetch_filters(ctx, result, attribute)
|
35
|
+
filter_attribute = ctx[:filters][attribute]
|
36
|
+
result[:filter] = {}
|
37
|
+
result[:name] = attribute
|
38
|
+
result[:filter][:handler] = filter_attribute[:with] || filter_attribute[:block]
|
39
|
+
end
|
46
40
|
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
def fetch_properties(result, attribute, value, properties)
|
42
|
+
splitter = Utils::Splitter.new attribute, value
|
43
|
+
PREDICATES.each do |predicate|
|
44
|
+
next unless splitter.split_key predicate
|
45
|
+
next unless properties.include?(splitter.field.to_sym)
|
46
|
+
|
47
|
+
result[:name] = splitter.field
|
48
|
+
result[:predicate] = predicate
|
50
49
|
end
|
50
|
+
end
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -4,7 +4,6 @@ module Trailblazer
|
|
4
4
|
class Finder
|
5
5
|
module Activities
|
6
6
|
class PrepareAdapter < Trailblazer::Activity::Railway
|
7
|
-
|
8
7
|
def set_adapter(ctx, **)
|
9
8
|
ctx[:adapter] = ctx.dig(:config, :adapter) || "Basic"
|
10
9
|
end
|
@@ -13,13 +12,13 @@ module Trailblazer
|
|
13
12
|
(ORM_ADAPTERS + ["Basic"]).include? adapter.to_s
|
14
13
|
end
|
15
14
|
|
16
|
-
def
|
15
|
+
def invalid?((ctx, _flow_options), **_circuit_options)
|
17
16
|
(ctx[:errors] ||= []) << {adapter: "The specified adapter are invalid"}
|
18
17
|
end
|
19
18
|
|
20
19
|
step :set_adapter
|
21
20
|
step :validate_adapter
|
22
|
-
fail :
|
21
|
+
fail :invalid?
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
@@ -5,7 +5,7 @@ module Trailblazer
|
|
5
5
|
module Activities
|
6
6
|
class PrepareEntity < Trailblazer::Activity::Railway
|
7
7
|
def validate_entity(ctx, **)
|
8
|
-
ctx.dig(:options
|
8
|
+
ctx.dig(:options, :entity) || ctx.dig(:config, :entity)
|
9
9
|
end
|
10
10
|
|
11
11
|
def invalid_entity_error(ctx, **)
|
@@ -13,7 +13,7 @@ module Trailblazer
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def set_entity(ctx, **)
|
16
|
-
ctx[:entity] = ctx.dig(:options
|
16
|
+
ctx[:entity] = ctx.dig(:options, :entity) || instance_eval(&ctx[:config][:entity])
|
17
17
|
end
|
18
18
|
|
19
19
|
step :validate_entity
|
@@ -12,8 +12,8 @@ module Trailblazer
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def set_paging(ctx, **)
|
15
|
-
ctx[:paging] = ctx.dig(:config
|
16
|
-
ctx[:paging][:current_page] = ctx.dig(:params
|
15
|
+
ctx[:paging] = ctx.dig(:config, :paging) || {}
|
16
|
+
ctx[:paging][:current_page] = ctx.dig(:params, :page) || 1
|
17
17
|
return true unless ctx[:params][:per_page]
|
18
18
|
|
19
19
|
ctx[:paging][:per_page] = ctx[:params][:per_page].to_i || ctx[:paging][:per_page]
|
@@ -18,11 +18,7 @@ module Trailblazer
|
|
18
18
|
return true if properties.empty?
|
19
19
|
|
20
20
|
properties.each do |key, _value|
|
21
|
-
|
22
|
-
return properties[key][:type].class.ancestors.include?(::Dry::Types::Definition)
|
23
|
-
else
|
24
|
-
return properties[key][:type].class.ancestors.include?(::Dry::Types::Nominal)
|
25
|
-
end
|
21
|
+
return properties[key][:type].class.ancestors.include?(::Dry::Types::Nominal)
|
26
22
|
end
|
27
23
|
end
|
28
24
|
|
@@ -4,7 +4,7 @@ module Trailblazer
|
|
4
4
|
class Finder
|
5
5
|
module Activities
|
6
6
|
class ProcessAdapters < Trailblazer::Activity::Railway
|
7
|
-
def set_adapter((ctx,
|
7
|
+
def set_adapter((ctx, _flow_options), **)
|
8
8
|
adapter = ctx[:adapter]
|
9
9
|
ctx[:orm] = {}
|
10
10
|
ctx[:orm][:adapter] = adapter
|
@@ -19,12 +19,18 @@ module Trailblazer
|
|
19
19
|
return true unless paginator
|
20
20
|
return false unless ORM_ADAPTERS.include?(ctx[:orm][:adapter])
|
21
21
|
return false unless PAGING_ADAPTERS.include?(paginator)
|
22
|
+
|
22
23
|
ctx[:orm][:paging] = "Trailblazer::Finder::Adapters::#{paginator}::Paging"
|
23
24
|
true
|
24
25
|
end
|
25
26
|
|
26
27
|
def invalid_paginator_error(ctx, **)
|
27
|
-
(ctx[:errors] ||= []) << {
|
28
|
+
(ctx[:errors] ||= []) << {
|
29
|
+
paginator: "Can't use paginator #{ctx.dig(
|
30
|
+
:config,
|
31
|
+
:paginator
|
32
|
+
)} without using an ORM like ActiveRecord or Sequel"
|
33
|
+
}
|
28
34
|
end
|
29
35
|
|
30
36
|
step :set_adapter, fast_track: true
|
@@ -10,7 +10,7 @@ module Trailblazer
|
|
10
10
|
module_function
|
11
11
|
|
12
12
|
def set_eq_handler
|
13
|
-
|
13
|
+
->(entity, attribute, value) do
|
14
14
|
return if Utils::String.blank?(value.to_s)
|
15
15
|
|
16
16
|
entity.where(attribute => value)
|
@@ -18,7 +18,7 @@ module Trailblazer
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def set_not_eq_handler
|
21
|
-
|
21
|
+
->(entity, attribute, value) do
|
22
22
|
return if Utils::String.blank?(value.to_s)
|
23
23
|
|
24
24
|
entity.where.not(attribute => value)
|
@@ -26,73 +26,73 @@ module Trailblazer
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def set_blank_handler
|
29
|
-
|
29
|
+
->(entity, attribute, _value) do
|
30
30
|
entity.where(attribute.to_sym => [nil, ""])
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
def set_not_blank_handler
|
35
|
-
|
35
|
+
->(entity, attribute, _value) do
|
36
36
|
entity.where.not(attribute.to_sym => [nil, ""])
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
def set_gt_handler
|
41
|
-
|
41
|
+
->(entity, attribute, value) do
|
42
42
|
entity.where("#{attribute} > ?", value.to_f)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def set_gte_handler
|
47
|
-
|
47
|
+
->(entity, attribute, value) do
|
48
48
|
entity.where("#{attribute} >= ?", value.to_f)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
def set_lt_handler
|
53
|
-
|
53
|
+
->(entity, attribute, value) do
|
54
54
|
entity.where("#{attribute} < ?", value.to_f)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
def set_lte_handler
|
59
|
-
|
59
|
+
->(entity, attribute, value) do
|
60
60
|
entity.where("#{attribute} <= ?", value.to_f)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
def set_cont_handler
|
65
|
-
|
65
|
+
->(entity, attribute, value) do
|
66
66
|
entity.where("#{attribute} LIKE ?", "%#{value}%")
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
def set_not_cont_handler
|
71
|
-
|
71
|
+
->(entity, attribute, value) do
|
72
72
|
entity.where("#{attribute} NOT LIKE ?", "%#{value}%")
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
def set_sw_handler
|
77
|
-
|
77
|
+
->(entity, attribute, value) do
|
78
78
|
entity.where("#{attribute} LIKE ?", "#{value}%")
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
def set_not_sw_handler
|
83
|
-
|
83
|
+
->(entity, attribute, value) do
|
84
84
|
entity.where("#{attribute} NOT LIKE ?", "#{value}%")
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
88
|
def set_ew_handler
|
89
|
-
|
89
|
+
->(entity, attribute, value) do
|
90
90
|
entity.where("#{attribute} LIKE ?", "%#{value}")
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
94
|
def set_not_ew_handler
|
95
|
-
|
95
|
+
->(entity, attribute, value) do
|
96
96
|
entity.where("#{attribute} NOT LIKE ?", "%#{value}")
|
97
97
|
end
|
98
98
|
end
|
@@ -10,7 +10,7 @@ module Trailblazer
|
|
10
10
|
module_function
|
11
11
|
|
12
12
|
def set_eq_handler
|
13
|
-
|
13
|
+
->(entity, attribute, value) do
|
14
14
|
return if Utils::String.blank?(value.to_s) || Utils::String.blank?(attribute.to_s)
|
15
15
|
|
16
16
|
Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_s == value.to_s && !v.nil? }, entity
|
@@ -18,7 +18,7 @@ module Trailblazer
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def set_not_eq_handler
|
21
|
-
|
21
|
+
->(entity, attribute, value) do
|
22
22
|
return if Utils::String.blank?(value.to_s)
|
23
23
|
|
24
24
|
Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_s != value.to_s && !v.nil? }, entity
|
@@ -26,43 +26,43 @@ module Trailblazer
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def set_blank_handler
|
29
|
-
|
29
|
+
->(entity, attribute, _value) do
|
30
30
|
Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && Utils::String.blank?(v.to_s) }, entity
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
def set_not_blank_handler
|
35
|
-
|
35
|
+
->(entity, attribute, _value) do
|
36
36
|
Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && !Utils::String.blank?(v.to_s) }, entity
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
def set_gt_handler
|
41
|
-
|
41
|
+
->(entity, attribute, value) do
|
42
42
|
Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_f > value.to_f }, entity
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def set_gte_handler
|
47
|
-
|
47
|
+
->(entity, attribute, value) do
|
48
48
|
Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_f >= value.to_f }, entity
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
def set_lt_handler
|
53
|
-
|
53
|
+
->(entity, attribute, value) do
|
54
54
|
Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_f < value.to_f }, entity
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
def set_lte_handler
|
59
|
-
|
59
|
+
->(entity, attribute, value) do
|
60
60
|
Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_i <= value.to_f }, entity
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
def set_cont_handler
|
65
|
-
|
65
|
+
->(entity, attribute, value) do
|
66
66
|
return if Utils::String.blank?(value.to_s) || Utils::String.blank?(attribute.to_s)
|
67
67
|
|
68
68
|
Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_s.include?(value.to_s) && !v.nil? }, entity
|
@@ -70,7 +70,7 @@ module Trailblazer
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def set_not_cont_handler
|
73
|
-
|
73
|
+
->(entity, attribute, value) do
|
74
74
|
return if Utils::String.blank?(value.to_s) || Utils::String.blank?(attribute.to_s)
|
75
75
|
|
76
76
|
Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && !v.to_s.include?(value.to_s) && !v.nil? }, entity
|
@@ -78,7 +78,7 @@ module Trailblazer
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def set_sw_handler
|
81
|
-
|
81
|
+
->(entity, attribute, value) do
|
82
82
|
return if Utils::String.blank?(value.to_s) || Utils::String.blank?(attribute.to_s)
|
83
83
|
|
84
84
|
Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_s.start_with?(value.to_s) && !v.nil? }, entity
|
@@ -86,7 +86,7 @@ module Trailblazer
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def set_not_sw_handler
|
89
|
-
|
89
|
+
->(entity, attribute, value) do
|
90
90
|
return if Utils::String.blank?(value.to_s) || Utils::String.blank?(attribute.to_s)
|
91
91
|
|
92
92
|
Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && !v.to_s.start_with?(value.to_s) && !v.nil? }, entity
|
@@ -94,7 +94,7 @@ module Trailblazer
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def set_ew_handler
|
97
|
-
|
97
|
+
->(entity, attribute, value) do
|
98
98
|
return if Utils::String.blank?(value.to_s) || Utils::String.blank?(attribute.to_s)
|
99
99
|
|
100
100
|
Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && v.to_s.end_with?(value.to_s) && !v.nil? }, entity
|
@@ -102,7 +102,7 @@ module Trailblazer
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def set_not_ew_handler
|
105
|
-
|
105
|
+
->(entity, attribute, value) do
|
106
106
|
return if Utils::String.blank?(value.to_s) || Utils::String.blank?(attribute.to_s)
|
107
107
|
|
108
108
|
Utils::Hash.deep_locate ->(k, v, _) { k == attribute.to_sym && !v.to_s.end_with?(value.to_s) && !v.nil? }, entity
|
@@ -10,7 +10,7 @@ module Trailblazer
|
|
10
10
|
module_function
|
11
11
|
|
12
12
|
def set_eq_handler
|
13
|
-
|
13
|
+
->(entity, attribute, value) do
|
14
14
|
return if Utils::String.blank?(value.to_s)
|
15
15
|
|
16
16
|
entity.where { ::Sequel[attribute.to_sym] =~ value }
|
@@ -18,7 +18,7 @@ module Trailblazer
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def set_not_eq_handler
|
21
|
-
|
21
|
+
->(entity, attribute, value) do
|
22
22
|
return if Utils::String.blank?(value.to_s)
|
23
23
|
|
24
24
|
entity.where { ::Sequel[attribute.to_sym] !~ value }
|
@@ -26,74 +26,74 @@ module Trailblazer
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def set_blank_handler
|
29
|
-
|
29
|
+
->(entity, attribute, _value) do
|
30
30
|
entity.where { ::Sequel.|({::Sequel[attribute.to_sym] => nil}, {::Sequel[attribute.to_sym] => ""}) }
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
def set_not_blank_handler
|
35
|
-
|
35
|
+
->(entity, attribute, _value) do
|
36
36
|
entity.exclude(::Sequel[attribute.to_sym] => nil, ::Sequel[attribute.to_sym] => "")
|
37
37
|
# entity.exclude(attribute.to_sym => nil).exclude(attribute.to_sym => "")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
def set_gt_handler
|
42
|
-
|
42
|
+
->(entity, attribute, value) do
|
43
43
|
entity.where { ::Sequel[attribute.to_sym] > value.to_f }
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
def set_gte_handler
|
48
|
-
|
48
|
+
->(entity, attribute, value) do
|
49
49
|
entity.where { ::Sequel[attribute.to_sym] >= value.to_f }
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
def set_lt_handler
|
54
|
-
|
54
|
+
->(entity, attribute, value) do
|
55
55
|
entity.where { ::Sequel[attribute.to_sym] < value.to_f }
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
def set_lte_handler
|
60
|
-
|
60
|
+
->(entity, attribute, value) do
|
61
61
|
entity.where { ::Sequel[attribute.to_sym] <= value.to_f }
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
def set_cont_handler
|
66
|
-
|
66
|
+
->(entity, attribute, value) do
|
67
67
|
entity.where(::Sequel.like(attribute.to_sym, "%#{value}%"))
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
def set_not_cont_handler
|
72
|
-
|
72
|
+
->(entity, attribute, value) do
|
73
73
|
entity.where(~::Sequel.like(attribute.to_sym, "%#{value}%"))
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
def set_sw_handler
|
78
|
-
|
78
|
+
->(entity, attribute, value) do
|
79
79
|
entity.where(::Sequel.like(attribute.to_sym, "#{value}%"))
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
def set_not_sw_handler
|
84
|
-
|
84
|
+
->(entity, attribute, value) do
|
85
85
|
entity.where(~::Sequel.like(attribute.to_sym, "#{value}%"))
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
def set_ew_handler
|
90
|
-
|
90
|
+
->(entity, attribute, value) do
|
91
91
|
entity.where(::Sequel.like(attribute.to_sym, "%#{value}"))
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
def set_not_ew_handler
|
96
|
-
|
96
|
+
->(entity, attribute, value) do
|
97
97
|
entity.where(~::Sequel.like(attribute.to_sym, "%#{value}"))
|
98
98
|
end
|
99
99
|
end
|
@@ -13,7 +13,7 @@ module Trailblazer
|
|
13
13
|
config[:entity] = block
|
14
14
|
end
|
15
15
|
|
16
|
-
def paging(options
|
16
|
+
def paging(**options)
|
17
17
|
config[:paging][:per_page] = options[:per_page] || 25
|
18
18
|
config[:paging][:min_per_page] = options[:min_per_page] || 10
|
19
19
|
config[:paging][:max_per_page] = options[:max_per_page] || 100
|
@@ -24,7 +24,8 @@ module Trailblazer
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def process_paging(ctx)
|
27
|
-
ctx.instance_exec @paging[:current_page], @paging[:per_page],
|
27
|
+
ctx.instance_exec @paging[:current_page], @paging[:per_page],
|
28
|
+
(@sorting.empty? ? (process_filters ctx) : (process_sorting ctx)), &@paging[:handler]
|
28
29
|
end
|
29
30
|
|
30
31
|
def process_sorting(ctx)
|
@@ -31,7 +31,10 @@ module Trailblazer
|
|
31
31
|
if sorting.nil?
|
32
32
|
params.merge! sort: "#{attribute} #{sort_direction_for(attribute)}"
|
33
33
|
elsif sorting.include?(attribute.to_s)
|
34
|
-
params.merge! sort: sorting.gsub(
|
34
|
+
params.merge! sort: sorting.gsub(
|
35
|
+
/#{attribute} #{sort_direction_for(attribute)}/,
|
36
|
+
"#{attribute} #{reverse_sort_direction_for(attribute)}"
|
37
|
+
)
|
35
38
|
else
|
36
39
|
params.merge! sort: "#{sorting}, #{attribute} #{sort_direction_for(attribute)}"
|
37
40
|
end
|
data/lib/trailblazer/finder.rb
CHANGED
@@ -33,14 +33,8 @@ require "trailblazer/operation/finder"
|
|
33
33
|
|
34
34
|
module Trailblazer
|
35
35
|
class Finder
|
36
|
-
DRY_TYPES_VERSION = Gem::Version.new(Dry::Types::VERSION)
|
37
|
-
LEGACY_DRY_TYPES = DRY_TYPES_VERSION <= Gem::Version.new('1')
|
38
36
|
module Types
|
39
|
-
|
40
|
-
include Dry::Types.module
|
41
|
-
else
|
42
|
-
include Dry.Types(default: :nominal)
|
43
|
-
end
|
37
|
+
include Dry.Types(default: :nominal)
|
44
38
|
end
|
45
39
|
|
46
40
|
include Base
|
@@ -12,13 +12,12 @@ Trailblazer::Operation.instance_eval do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class Finder
|
15
|
-
def call(ctx, options
|
15
|
+
def call(ctx, **options)
|
16
16
|
builder = Finder::Builder.new
|
17
17
|
ctx[:finder] = finder = builder.call(options, options[:params])
|
18
18
|
ctx[:model] = finder # Don't like it, but somehow it's needed if contracts are loaded
|
19
19
|
ctx[:"result.finder"] = Trailblazer::Operation::Result.new(!finder.nil?, {})
|
20
20
|
|
21
|
-
|
22
21
|
ctx[:"result.finder"].success?
|
23
22
|
end
|
24
23
|
|
@@ -49,6 +48,7 @@ Trailblazer::Operation.instance_eval do
|
|
49
48
|
|
50
49
|
def apply_id(params)
|
51
50
|
return if params[:id].nil?
|
51
|
+
|
52
52
|
params[:id_eq] = params[:id]
|
53
53
|
end
|
54
54
|
end
|