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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d90691d88aed4c8d7e43ccd1fd4160ed6f445b7915becf4c76bd025ca4d0f661
4
- data.tar.gz: e66c8f81873325b16f81e2d4ae9b99111f16a704c54d01de24bcac27bdb1d479
3
+ metadata.gz: 1878b1acf62f66eb1c410b476037ab0c0aa45b761805f151fe987f6d81b24ecc
4
+ data.tar.gz: 27e69700c5507481a8c06828889d451c98976c92a1b8542602565ecf438461e0
5
5
  SHA512:
6
- metadata.gz: c2af6f7a7e82d96a8385d23d88702501881eee63ee2a23e0308a4a2a4eaca9c217721df62479088f03716a1adc3e790f18b32fb26de76685b1e6aef4459d3fe8
7
- data.tar.gz: 7f44b76f696ce6788584c7a97f703e5e4b4e4ced2a39fded2f672ad3468623f3e161a868bfc6861cdf1d4d5117f1eb57f28ebe0816fae8f78a48b1a7b75c2604
6
+ metadata.gz: fe66baf784a25237ee917eee6c261af6dba12e4f5e63df164a1cc37d268fad4b893c315594c2aea9d4083fc20ab3fedab50baf52a447dc198ea19ae0b260cc38
7
+ data.tar.gz: 50051b6a1e6a8413c1d4d70d455310fa2f4114e598737c0334fe1f1a0124906227c77f42d01e4722e76b352fc6ca55af1beef90f50309bf2d8ffd8690e034f4a
data/CHANGES.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 0.10.3
2
+ * Add support for strings in filters keys.
3
+
1
4
  # 0.10.2
2
5
  * Add support for ActiveSupport::Hash as params
3
6
 
@@ -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, attribute) || result if ctx[:filters].include?(attribute)
16
- fetch_properties(result, attribute, value, ctx[: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][attribute] = result.merge!(value: value)
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 (:validate_entity)
20
- fail (:invalid_entity_error)
21
- step (:set_entity)
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 (:check_paging),
31
- Output(:failure) => Track(:end_paging)
32
- step (:set_paging),
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 (:validate_params)
22
- fail (:invalid_params_error)
23
- step (:set_params)
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 (:check_sorting),
41
- Output(:success) => Track(:paging),
40
+ step :check_sorting,
42
41
  Output(:failure) => Track(:end_sorting)
43
- step (:set_sorting),
44
- magnetic_to: :paging,
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
- config[:filters][name] = {}
30
- config[:filters][name][:name] = name
31
- config[:filters][name][:with] = options[:with] if options.include?(:with)
32
- config[:filters][name][:block] = block || nil
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)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Trailblazer
4
4
  class Finder
5
- VERSION = "0.10.2".freeze
5
+ VERSION = "0.10.3".freeze
6
6
  end
7
7
  end
@@ -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
- 20.times { |i| Product.create name: "product_#{i}" }
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
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.10.2
4
+ version: 0.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer