trailblazer-finder 0.50.0 → 0.70.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +16 -0
- data/.rubocop.yml +7 -1
- data/CHANGES.md +6 -0
- data/Gemfile +3 -1
- data/Rakefile +0 -6
- 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/spec/spec_helper.rb +0 -1
- data/spec/trailblazer/finder/adapters/active_record_spec.rb +4 -4
- data/spec/trailblazer/finder/adapters/basic_spec.rb +12 -3
- data/spec/trailblazer/finder/adapters/kaminari_spec.rb +1 -1
- data/spec/trailblazer/finder/adapters/sequel_spec.rb +4 -4
- data/spec/trailblazer/operation/finder_spec.rb +0 -1
- data/trailblazer-finder.gemspec +4 -5
- metadata +20 -34
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39f554fa2720ae7fe8f7bdc61eb44e636167a7ec85cb4c0b47da5027f80d4c3e
|
4
|
+
data.tar.gz: 83e4e41732b0c4fef9d4d5793e3f6de7ad6b66086c906854127e6018f7a7eaa5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8e69bb8c68980e657d2399fb1e6b50d63b1538e38346eb1a40465e60737940f431c052689a29c3b4ca9fdfc69b6e7d26f49f59db015e30beb5ba736522e81e5
|
7
|
+
data.tar.gz: 9fe89ed1a67614bff0a9d5a69242972ce4bd219b0d20e72bb0d356637f7dbc9c2f3ea6e27fd32eb42c32e5502e67716545f4be5e9498a3d94c3863c92e4db1e0
|
@@ -0,0 +1,16 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
strategy:
|
6
|
+
fail-fast: false
|
7
|
+
matrix:
|
8
|
+
ruby: [2.5, 2.6, 2.7, '3.0']
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v2
|
12
|
+
- uses: ruby/setup-ruby@v1
|
13
|
+
with:
|
14
|
+
ruby-version: ${{ matrix.ruby }}
|
15
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
16
|
+
- run: bundle exec rake
|
data/.rubocop.yml
CHANGED
@@ -2,4 +2,10 @@ require: rubocop-rspec
|
|
2
2
|
|
3
3
|
inherit_from:
|
4
4
|
- https://raw.githubusercontent.com/trailblazer/meta/master/rubocop.yml
|
5
|
-
|
5
|
+
|
6
|
+
RSpec/ExampleLength:
|
7
|
+
Enabled: false
|
8
|
+
RSpec/MultipleExpectations:
|
9
|
+
Enabled: false
|
10
|
+
Layout/LineLength:
|
11
|
+
Enabled: false
|
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
@@ -4,7 +4,9 @@ source "https://rubygems.org"
|
|
4
4
|
|
5
5
|
gemspec
|
6
6
|
|
7
|
-
gem "
|
7
|
+
gem "debug", platform: :mri
|
8
|
+
gem "jdbc-sqlite3", :platform => :jruby
|
9
|
+
gem "sqlite3", platform: :mri
|
8
10
|
|
9
11
|
# Had to add this for a bit, since none of the latest changes have been pushed to gems yet
|
10
12
|
# gem "trailblazer", github: "trailblazer/trailblazer"
|
data/Rakefile
CHANGED
@@ -16,12 +16,6 @@ end
|
|
16
16
|
|
17
17
|
RuboCop::RakeTask.new(:rubocop)
|
18
18
|
|
19
|
-
desc "Remove temporary files"
|
20
|
-
task :clean do
|
21
|
-
`rm -rf *.gem doc pkg coverage test-reports`
|
22
|
-
%x(rm -f `find . -name '*.rbc'`)
|
23
|
-
end
|
24
|
-
|
25
19
|
desc "Build the gem"
|
26
20
|
task :gem do
|
27
21
|
`gem build trailblazer-finder.gemspec`
|
@@ -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
|
data/spec/spec_helper.rb
CHANGED
@@ -132,7 +132,7 @@ module Trailblazer
|
|
132
132
|
|
133
133
|
it "sets the property and works with sw predicate" do
|
134
134
|
5.times { |i| Product.create name: "product_#{i}" }
|
135
|
-
|
135
|
+
Product.create name: "predicate_0"
|
136
136
|
4.times { |i| Product.create name: "none_#{i}" }
|
137
137
|
finder = new_finder name_sw: "pr" do
|
138
138
|
property :name, type: Types::String
|
@@ -144,7 +144,7 @@ module Trailblazer
|
|
144
144
|
|
145
145
|
it "sets the property and works with not_sw predicate" do
|
146
146
|
5.times { |i| Product.create name: "product_#{i}" }
|
147
|
-
|
147
|
+
Product.create name: "predicate_0"
|
148
148
|
4.times { |i| Product.create name: "none_#{i}" }
|
149
149
|
finder = new_finder name_not_sw: "pr" do
|
150
150
|
property :name, type: Types::String
|
@@ -156,7 +156,7 @@ module Trailblazer
|
|
156
156
|
|
157
157
|
it "sets the property and works with ew predicate" do
|
158
158
|
5.times { |i| Product.create name: "product_#{i}_end" }
|
159
|
-
|
159
|
+
Product.create name: "predicate_0_endwow"
|
160
160
|
4.times { |i| Product.create name: "none_#{i}" }
|
161
161
|
finder = new_finder name_ew: "end" do
|
162
162
|
property :name, type: Types::String
|
@@ -168,7 +168,7 @@ module Trailblazer
|
|
168
168
|
|
169
169
|
it "sets the property and works with not_ew predicate" do
|
170
170
|
5.times { |i| Product.create name: "product_#{i}_end" }
|
171
|
-
|
171
|
+
Product.create name: "predicate_0_endwow"
|
172
172
|
4.times { |i| Product.create name: "none_#{i}" }
|
173
173
|
finder = new_finder name_not_ew: "end" do
|
174
174
|
property :name, type: Types::String
|
@@ -173,7 +173,10 @@ module Trailblazer
|
|
173
173
|
end
|
174
174
|
|
175
175
|
it "accepts per_page as a parameter" do
|
176
|
-
entity = [
|
176
|
+
entity = [
|
177
|
+
{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}, {id: 4, value: "Test 4"},
|
178
|
+
{id: 5, value: "Test 5"}, {id: 6, value: "Test 6"}, {id: 7, value: "Test 7"}, {id: 8, value: "Test 8"}, {id: 9, value: "Test 9"}, {id: 10, value: "Test 10"}
|
179
|
+
]
|
177
180
|
finder = new_finder entity, page: 2, per_page: 4 do
|
178
181
|
paging per_page: 5, min_per_page: 2, max_per_page: 8
|
179
182
|
end
|
@@ -183,7 +186,10 @@ module Trailblazer
|
|
183
186
|
end
|
184
187
|
|
185
188
|
it "uses max_per_page in finder as maximum per_page" do
|
186
|
-
entity = [
|
189
|
+
entity = [
|
190
|
+
{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}, {id: 4, value: "Test 4"},
|
191
|
+
{id: 5, value: "Test 5"}, {id: 6, value: "Test 6"}, {id: 7, value: "Test 7"}, {id: 8, value: "Test 8"}, {id: 9, value: "Test 9"}, {id: 10, value: "Test 10"}
|
192
|
+
]
|
187
193
|
finder = new_finder entity, page: 2, per_page: 9 do
|
188
194
|
paging per_page: 5, min_per_page: 2, max_per_page: 8
|
189
195
|
end
|
@@ -193,7 +199,10 @@ module Trailblazer
|
|
193
199
|
end
|
194
200
|
|
195
201
|
it "uses min_per_page in finder as minimum per_page" do
|
196
|
-
entity = [
|
202
|
+
entity = [
|
203
|
+
{id: 1, value: "Test 1"}, {id: 2, value: "Test 2"}, {id: 3, value: "Test 3"}, {id: 4, value: "Test 4"},
|
204
|
+
{id: 5, value: "Test 5"}, {id: 6, value: "Test 6"}, {id: 7, value: "Test 7"}, {id: 8, value: "Test 8"}, {id: 9, value: "Test 9"}, {id: 10, value: "Test 10"}
|
205
|
+
]
|
197
206
|
finder = new_finder entity, page: 2, per_page: 1 do
|
198
207
|
paging per_page: 5, min_per_page: 2, max_per_page: 8
|
199
208
|
end
|
@@ -59,7 +59,7 @@ module Trailblazer
|
|
59
59
|
it "accepts per_page as a parameter" do
|
60
60
|
10.times { |i| Product.create name: "product_#{i}" }
|
61
61
|
finder = new_finder page: 2, per_page: 4 do
|
62
|
-
|
62
|
+
adapter "ActiveRecord"
|
63
63
|
paginator "Kaminari"
|
64
64
|
paging per_page: 5, min_per_page: 2, max_per_page: 8
|
65
65
|
end
|
@@ -132,7 +132,7 @@ module Trailblazer
|
|
132
132
|
|
133
133
|
it "sets the property and works with sw predicate" do
|
134
134
|
5.times { |i| SProduct.create name: "product_#{i}" }
|
135
|
-
|
135
|
+
SProduct.create name: "predicate_0"
|
136
136
|
4.times { |i| SProduct.create name: "none_#{i}" }
|
137
137
|
finder = new_finder name_sw: "pr" do
|
138
138
|
property :name, type: Types::String
|
@@ -144,7 +144,7 @@ module Trailblazer
|
|
144
144
|
|
145
145
|
it "sets the property and works with not_sw predicate" do
|
146
146
|
5.times { |i| SProduct.create name: "product_#{i}" }
|
147
|
-
|
147
|
+
SProduct.create name: "predicate_0"
|
148
148
|
4.times { |i| SProduct.create name: "none_#{i}" }
|
149
149
|
finder = new_finder name_not_sw: "pr" do
|
150
150
|
property :name, type: Types::String
|
@@ -156,7 +156,7 @@ module Trailblazer
|
|
156
156
|
|
157
157
|
it "sets the property and works with ew predicate" do
|
158
158
|
5.times { |i| SProduct.create name: "product_#{i}_end" }
|
159
|
-
|
159
|
+
SProduct.create name: "predicate_0_endwow"
|
160
160
|
4.times { |i| SProduct.create name: "none_#{i}" }
|
161
161
|
finder = new_finder name_ew: "end" do
|
162
162
|
property :name, type: Types::String
|
@@ -168,7 +168,7 @@ module Trailblazer
|
|
168
168
|
|
169
169
|
it "sets the property and works with not_ew predicate" do
|
170
170
|
5.times { |i| SProduct.create name: "product_#{i}_end" }
|
171
|
-
|
171
|
+
SProduct.create name: "predicate_0_endwow"
|
172
172
|
4.times { |i| SProduct.create name: "none_#{i}" }
|
173
173
|
finder = new_finder name_not_ew: "end" do
|
174
174
|
property :name, type: Types::String
|
data/trailblazer-finder.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "dry-types"
|
20
|
+
spec.add_dependency "dry-types", ">= 1.0.0"
|
21
21
|
spec.add_dependency "trailblazer-activity", ">= 0.10.0"
|
22
22
|
|
23
23
|
spec.add_development_dependency "activerecord"
|
@@ -26,16 +26,15 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "kaminari-activerecord"
|
27
27
|
spec.add_development_dependency "rake"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.5"
|
29
|
-
spec.add_development_dependency "rspec-mocks", "~> 3.5"
|
30
29
|
spec.add_development_dependency "rspec_junit_formatter"
|
30
|
+
spec.add_development_dependency "rspec-mocks", "~> 3.5"
|
31
31
|
spec.add_development_dependency "rubocop"
|
32
32
|
spec.add_development_dependency "rubocop-rspec"
|
33
33
|
spec.add_development_dependency "sequel"
|
34
34
|
spec.add_development_dependency "simplecov"
|
35
|
-
spec.add_development_dependency "sqlite3"
|
36
35
|
spec.add_development_dependency "trailblazer", "~> 2.1.0"
|
37
|
-
spec.add_development_dependency "will_paginate"
|
38
36
|
spec.add_development_dependency "trailblazer-developer"
|
37
|
+
spec.add_development_dependency "will_paginate"
|
39
38
|
|
40
|
-
spec.required_ruby_version = ">= 2.
|
39
|
+
spec.required_ruby_version = ">= 2.5.0"
|
41
40
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.70.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
- Marc Tich
|
9
9
|
- Abdelkader Boudih
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-11-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: dry-types
|
@@ -18,14 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 1.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
28
|
+
version: 1.0.0
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: trailblazer-activity
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,20 +124,6 @@ dependencies:
|
|
124
124
|
- - "~>"
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '3.5'
|
127
|
-
- !ruby/object:Gem::Dependency
|
128
|
-
name: rspec-mocks
|
129
|
-
requirement: !ruby/object:Gem::Requirement
|
130
|
-
requirements:
|
131
|
-
- - "~>"
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
version: '3.5'
|
134
|
-
type: :development
|
135
|
-
prerelease: false
|
136
|
-
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
requirements:
|
138
|
-
- - "~>"
|
139
|
-
- !ruby/object:Gem::Version
|
140
|
-
version: '3.5'
|
141
127
|
- !ruby/object:Gem::Dependency
|
142
128
|
name: rspec_junit_formatter
|
143
129
|
requirement: !ruby/object:Gem::Requirement
|
@@ -153,21 +139,21 @@ dependencies:
|
|
153
139
|
- !ruby/object:Gem::Version
|
154
140
|
version: '0'
|
155
141
|
- !ruby/object:Gem::Dependency
|
156
|
-
name:
|
142
|
+
name: rspec-mocks
|
157
143
|
requirement: !ruby/object:Gem::Requirement
|
158
144
|
requirements:
|
159
|
-
- - "
|
145
|
+
- - "~>"
|
160
146
|
- !ruby/object:Gem::Version
|
161
|
-
version: '
|
147
|
+
version: '3.5'
|
162
148
|
type: :development
|
163
149
|
prerelease: false
|
164
150
|
version_requirements: !ruby/object:Gem::Requirement
|
165
151
|
requirements:
|
166
|
-
- - "
|
152
|
+
- - "~>"
|
167
153
|
- !ruby/object:Gem::Version
|
168
|
-
version: '
|
154
|
+
version: '3.5'
|
169
155
|
- !ruby/object:Gem::Dependency
|
170
|
-
name: rubocop
|
156
|
+
name: rubocop
|
171
157
|
requirement: !ruby/object:Gem::Requirement
|
172
158
|
requirements:
|
173
159
|
- - ">="
|
@@ -181,7 +167,7 @@ dependencies:
|
|
181
167
|
- !ruby/object:Gem::Version
|
182
168
|
version: '0'
|
183
169
|
- !ruby/object:Gem::Dependency
|
184
|
-
name:
|
170
|
+
name: rubocop-rspec
|
185
171
|
requirement: !ruby/object:Gem::Requirement
|
186
172
|
requirements:
|
187
173
|
- - ">="
|
@@ -195,7 +181,7 @@ dependencies:
|
|
195
181
|
- !ruby/object:Gem::Version
|
196
182
|
version: '0'
|
197
183
|
- !ruby/object:Gem::Dependency
|
198
|
-
name:
|
184
|
+
name: sequel
|
199
185
|
requirement: !ruby/object:Gem::Requirement
|
200
186
|
requirements:
|
201
187
|
- - ">="
|
@@ -209,7 +195,7 @@ dependencies:
|
|
209
195
|
- !ruby/object:Gem::Version
|
210
196
|
version: '0'
|
211
197
|
- !ruby/object:Gem::Dependency
|
212
|
-
name:
|
198
|
+
name: simplecov
|
213
199
|
requirement: !ruby/object:Gem::Requirement
|
214
200
|
requirements:
|
215
201
|
- - ">="
|
@@ -237,7 +223,7 @@ dependencies:
|
|
237
223
|
- !ruby/object:Gem::Version
|
238
224
|
version: 2.1.0
|
239
225
|
- !ruby/object:Gem::Dependency
|
240
|
-
name:
|
226
|
+
name: trailblazer-developer
|
241
227
|
requirement: !ruby/object:Gem::Requirement
|
242
228
|
requirements:
|
243
229
|
- - ">="
|
@@ -251,7 +237,7 @@ dependencies:
|
|
251
237
|
- !ruby/object:Gem::Version
|
252
238
|
version: '0'
|
253
239
|
- !ruby/object:Gem::Dependency
|
254
|
-
name:
|
240
|
+
name: will_paginate
|
255
241
|
requirement: !ruby/object:Gem::Requirement
|
256
242
|
requirements:
|
257
243
|
- - ">="
|
@@ -273,9 +259,9 @@ executables: []
|
|
273
259
|
extensions: []
|
274
260
|
extra_rdoc_files: []
|
275
261
|
files:
|
262
|
+
- ".github/workflows/ci.yml"
|
276
263
|
- ".gitignore"
|
277
264
|
- ".rubocop.yml"
|
278
|
-
- ".travis.yml"
|
279
265
|
- CHANGES.md
|
280
266
|
- Gemfile
|
281
267
|
- LICENSE.txt
|
@@ -340,7 +326,7 @@ homepage: http://trailblazer.to
|
|
340
326
|
licenses:
|
341
327
|
- LGPL-3.0
|
342
328
|
metadata: {}
|
343
|
-
post_install_message:
|
329
|
+
post_install_message:
|
344
330
|
rdoc_options: []
|
345
331
|
require_paths:
|
346
332
|
- lib
|
@@ -348,7 +334,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
348
334
|
requirements:
|
349
335
|
- - ">="
|
350
336
|
- !ruby/object:Gem::Version
|
351
|
-
version: 2.
|
337
|
+
version: 2.5.0
|
352
338
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
353
339
|
requirements:
|
354
340
|
- - ">="
|
@@ -356,7 +342,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
356
342
|
version: '0'
|
357
343
|
requirements: []
|
358
344
|
rubygems_version: 3.0.3
|
359
|
-
signing_key:
|
345
|
+
signing_key:
|
360
346
|
specification_version: 4
|
361
347
|
summary: Trailblazer based finder objects. It is designed to be used on its own as
|
362
348
|
a separate gem. It was influenced by popular Ransack gem, but in addition to ActiveRecord,
|