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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trailblazer/finder/activities/find.rb +16 -16
  3. data/lib/trailblazer/finder/activities/prepare_adapter.rb +2 -3
  4. data/lib/trailblazer/finder/activities/prepare_entity.rb +2 -2
  5. data/lib/trailblazer/finder/activities/prepare_paging.rb +2 -2
  6. data/lib/trailblazer/finder/activities/prepare_properties.rb +1 -5
  7. data/lib/trailblazer/finder/activities/process_adapters.rb +8 -2
  8. data/lib/trailblazer/finder/adapters/active_record/paging.rb +1 -1
  9. data/lib/trailblazer/finder/adapters/active_record/predicates.rb +14 -14
  10. data/lib/trailblazer/finder/adapters/active_record/sorting.rb +1 -1
  11. data/lib/trailblazer/finder/adapters/basic/paging.rb +1 -1
  12. data/lib/trailblazer/finder/adapters/basic/predicates.rb +14 -14
  13. data/lib/trailblazer/finder/adapters/basic/sorting.rb +1 -1
  14. data/lib/trailblazer/finder/adapters/kaminari/paging.rb +1 -1
  15. data/lib/trailblazer/finder/adapters/sequel/paging.rb +1 -1
  16. data/lib/trailblazer/finder/adapters/sequel/predicates.rb +14 -14
  17. data/lib/trailblazer/finder/adapters/sequel/sorting.rb +1 -1
  18. data/lib/trailblazer/finder/adapters/will_paginate/paging.rb +1 -1
  19. data/lib/trailblazer/finder/dsl.rb +1 -1
  20. data/lib/trailblazer/finder/find.rb +2 -1
  21. data/lib/trailblazer/finder/helpers/sorting.rb +4 -1
  22. data/lib/trailblazer/finder/version.rb +1 -1
  23. data/lib/trailblazer/finder.rb +1 -7
  24. data/lib/trailblazer/operation/finder.rb +2 -2
  25. data/trailblazer-finder.gemspec +8 -8
  26. metadata +26 -57
  27. data/.gitignore +0 -24
  28. data/.rubocop.yml +0 -5
  29. data/.travis.yml +0 -7
  30. data/CHANGES.md +0 -40
  31. data/Gemfile +0 -14
  32. data/LICENSE.txt +0 -9
  33. data/README.md +0 -451
  34. data/Rakefile +0 -31
  35. data/spec/spec_helper.rb +0 -14
  36. data/spec/spec_helper_active_record.rb +0 -48
  37. data/spec/spec_helper_sequel.rb +0 -33
  38. data/spec/spec_helper_will_paginate.rb +0 -13
  39. data/spec/trailblazer/finder/adapters/active_record_spec.rb +0 -267
  40. data/spec/trailblazer/finder/adapters/basic_spec.rb +0 -251
  41. data/spec/trailblazer/finder/adapters/kaminari_spec.rb +0 -115
  42. data/spec/trailblazer/finder/adapters/sequel_spec.rb +0 -267
  43. data/spec/trailblazer/finder/adapters/will_paginate_spec.rb +0 -117
  44. data/spec/trailblazer/finder/base_spec.rb +0 -417
  45. data/spec/trailblazer/finder/dsl_spec.rb +0 -204
  46. data/spec/trailblazer/finder/utils/hash_spec.rb +0 -26
  47. data/spec/trailblazer/finder/utils/splitter_spec.rb +0 -39
  48. data/spec/trailblazer/finder/utils/string_spec.rb +0 -69
  49. data/spec/trailblazer/operation/finder_spec.rb +0 -122
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfcac8d017065a8faea558faebaa1bd9e742b7ceb9444a50eafd79d2c759bbfc
4
- data.tar.gz: fdfafe463cba185afb34934f981b3428bb357a4031f941e22cb44e1c45608e11
3
+ metadata.gz: d9ed5fd3c089acb644a3c240478b2aae6b028f63108a94fba82e3afb9164e226
4
+ data.tar.gz: 155a516ced78ae4621595ec091e5cf5c651d187949961ddc793b3d57bc10aaf9
5
5
  SHA512:
6
- metadata.gz: 89c313cc891e5ef6b1d6e07145e23541d74698b543e47f4213d621e21925ec18c60d01d66cdbc2c6fe9d2ddbbfc4d5ef201f1bb80a1264ffe70c01f3e37772e0
7
- data.tar.gz: 2a00366ecc9c10ae045ce1d1c69f455cc7a8b101be8bb360228cf8cb148833502ea6039ce30740781bd93f97c8cabf878a6129beeb072c9e4e6e0b13b5c3128f
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
- 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)
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
- result[:name] = splitter.field
48
- result[:predicate] = predicate
49
- end
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 is_invalid?((ctx, _flow_options), **_circuit_options)
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 :is_invalid?
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,:entity) || ctx.dig(:config,:entity)
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,:entity) || instance_eval(&ctx[:config][:entity])
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,:paging) || {}
16
- ctx[:paging][:current_page] = ctx.dig(:params,:page) || 1
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
- if LEGACY_DRY_TYPES
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, flow_options), **)
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] ||= []) << {paginator: "Can't use paginator #{ctx.dig(:config, :paginator)} without using an ORM like ActiveRecord or Sequel"}
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_paging_handler
13
- lambda do |current_page, per_page, entity|
13
+ ->(current_page, per_page, entity) do
14
14
  entity.limit(per_page).offset(([current_page, 1].max - 1) * per_page)
15
15
  end
16
16
  end
@@ -10,7 +10,7 @@ module Trailblazer
10
10
  module_function
11
11
 
12
12
  def set_eq_handler
13
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, _value|
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
- lambda do |entity, attribute, _value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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_sorting_handler
13
- lambda do |sort_attributes, entity|
13
+ ->(sort_attributes, entity) do
14
14
  sort_attributes.delete(:handler)
15
15
  attributes = []
16
16
  sort_attributes.each do |attr|
@@ -10,7 +10,7 @@ module Trailblazer
10
10
  module_function
11
11
 
12
12
  def set_paging_handler
13
- lambda do |current_page, per_page, entity|
13
+ ->(current_page, per_page, entity) do
14
14
  entity.drop(([current_page, 1].max - 1) * per_page).first(per_page)
15
15
  end
16
16
  end
@@ -10,7 +10,7 @@ module Trailblazer
10
10
  module_function
11
11
 
12
12
  def set_eq_handler
13
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, _value|
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
- lambda do |entity, attribute, _value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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_sorting_handler
13
- lambda do |sort_attributes, entity|
13
+ ->(sort_attributes, entity) do
14
14
  sort_attributes.delete(:handler)
15
15
  attributes = []
16
16
  sort_attributes.each do |attr|
@@ -9,7 +9,7 @@ module Trailblazer
9
9
  module_function
10
10
 
11
11
  def set_paging_handler
12
- lambda do |current_page, per_page, entity|
12
+ ->(current_page, per_page, entity) do
13
13
  entity.page(current_page).per(per_page)
14
14
  end
15
15
  end
@@ -10,7 +10,7 @@ module Trailblazer
10
10
  module_function
11
11
 
12
12
  def set_paging_handler
13
- lambda do |current_page, per_page, entity|
13
+ ->(current_page, per_page, entity) do
14
14
  entity.limit(per_page).offset(([current_page, 1].max - 1) * per_page)
15
15
  end
16
16
  end
@@ -10,7 +10,7 @@ module Trailblazer
10
10
  module_function
11
11
 
12
12
  def set_eq_handler
13
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, _value|
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
- lambda do |entity, attribute, _value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
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
- lambda do |entity, attribute, value|
96
+ ->(entity, attribute, value) do
97
97
  entity.where(~::Sequel.like(attribute.to_sym, "%#{value}"))
98
98
  end
99
99
  end
@@ -10,7 +10,7 @@ module Trailblazer
10
10
  module_function
11
11
 
12
12
  def set_sorting_handler
13
- lambda do |sort_attributes, entity|
13
+ ->(sort_attributes, entity) do
14
14
  sort_attributes.delete(:handler)
15
15
  attributes = []
16
16
  sort_attributes.each do |attr|
@@ -9,7 +9,7 @@ module Trailblazer
9
9
  module_function
10
10
 
11
11
  def set_paging_handler
12
- lambda do |current_page, per_page, entity|
12
+ ->(current_page, per_page, entity) do
13
13
  entity.paginate per_page: per_page, page: current_page.zero? ? nil : current_page
14
14
  end
15
15
  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], (@sorting.empty? ? (process_filters ctx) : (process_sorting ctx)), &@paging[:handler]
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(/#{attribute} #{sort_direction_for(attribute)}/, "#{attribute} #{reverse_sort_direction_for(attribute)}")
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Trailblazer
4
4
  class Finder
5
- VERSION = "0.50.0".freeze
5
+ VERSION = "0.80.1"
6
6
  end
7
7
  end
@@ -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
- if LEGACY_DRY_TYPES
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