trailblazer-finder 0.80.1 → 0.90.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9ed5fd3c089acb644a3c240478b2aae6b028f63108a94fba82e3afb9164e226
4
- data.tar.gz: 155a516ced78ae4621595ec091e5cf5c651d187949961ddc793b3d57bc10aaf9
3
+ metadata.gz: 0c3605d464db4d05bd07e54aec870bd62820657704a730ebc02d11f904dcd964
4
+ data.tar.gz: e0c677b1cf39def27bef24b5787cf0cc6a475afb9adf227baa77315ee447208b
5
5
  SHA512:
6
- metadata.gz: dec5f359b98b15578b1bc38f521a43200bfe5f68b92daa3e70e2274bfc0a6e43503564dc012f0478af51f3fd2afdb22dc0b8293239c2919508d0ab2158117dfa
7
- data.tar.gz: 363bc66d7057c76290622ed083aaa270896ef956ca16019d63d8c653fd95630764fd116f6df052e9061e8c5442eaec0dec6e130c159a92e829c79e37251f01fa
6
+ metadata.gz: 251cf565e7ca50200c70a997bbbe8c96d28232b28d8bd8001129612194ee2065f57b6198b965cb60f19420f988ad1af17cdcd50c4ad23a50d6eff2241d4a2845
7
+ data.tar.gz: dcad67e86a906c097f00b88b6b051b296819287a1401db159c401121142e794028a0a0406b8836fc74f590c368ac6a21045f39ed869d36e7b1f6642495c8ae91
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Trailblazer
4
4
  class Finder
5
- VERSION = "0.80.1"
5
+ VERSION = "0.90.0"
6
6
  end
7
7
  end
@@ -1,55 +1,57 @@
1
- # Really gotta clean this up, but can't be bothered right now
2
- Trailblazer::Operation.instance_eval do
3
- def self.Finder(finder_class, action = nil, entity = nil)
4
- task = Trailblazer::Activity::TaskBuilder::Binary(Finder.new)
5
- injection = Trailblazer::Activity::TaskWrap::Inject::Defaults::Extension(
6
- :"finder.class" => finder_class,
7
- :"finder.entity" => entity,
8
- :"finder.action" => action
9
- )
10
-
11
- {task: task, id: "finder.build", extensions: [injection]}
12
- end
13
-
14
- class Finder
15
- def call(ctx, **options)
16
- builder = Finder::Builder.new
17
- ctx[:finder] = finder = builder.call(options, options[:params])
18
- ctx[:model] = finder # Don't like it, but somehow it's needed if contracts are loaded
19
- ctx[:"result.finder"] = Trailblazer::Operation::Result.new(!finder.nil?, {})
20
-
21
- ctx[:"result.finder"].success?
1
+ module Trailblazer
2
+ class Operation
3
+ def self.Finder(finder_class, action = nil, entity = nil)
4
+ task = Trailblazer::Activity::TaskBuilder::Binary(Finder.new)
5
+ injections = [
6
+ :params,
7
+ {:"finder.class" => ->(*) { finder_class }},
8
+ {:"finder.entity" => ->(*) { entity }},
9
+ {:"finder.action" => ->(*) { action }}
10
+ ]
11
+
12
+ {task: task, id: "finder.build", inject: injections}
22
13
  end
23
14
 
24
- class Builder
25
- def call(options, params)
26
- finder_class = options[:"finder.class"]
27
- entity = options[:"finder.entity"]
28
- action = options[:"finder.action"]
29
- action = :all unless %i[all single].include?(action)
15
+ class Finder
16
+ def call(ctx, **options)
17
+ builder = Finder::Builder.new
18
+ ctx[:finder] = finder = builder.call(options, options[:params])
19
+ ctx[:model] = finder # Don't like it, but somehow it's needed if contracts are loaded
20
+ ctx[:"result.finder"] = Trailblazer::Operation::Result.new(!finder.nil?, {})
30
21
 
31
- send("#{action}!", finder_class, entity, params, options[:"finder.action"])
22
+ ctx[:"result.finder"].success?
32
23
  end
33
24
 
34
- private
25
+ class Builder
26
+ def call(options, params)
27
+ finder_class = options[:"finder.class"]
28
+ entity = options[:"finder.entity"]
29
+ action = options[:"finder.action"]
30
+ action = :all unless %i[all single].include?(action)
35
31
 
36
- def all!(finder_class, entity, params, *)
37
- finder_class.new(entity: entity, params: params)
38
- end
32
+ send("#{action}!", finder_class, entity, params, options[:"finder.action"])
33
+ end
39
34
 
40
- def single!(finder_class, entity, params, *)
41
- apply_id(params)
42
- if entity.nil?
43
- finder_class.new(params: params).result.first
44
- else
45
- finder_class.new(entity: entity, params: params).result.first
35
+ private
36
+
37
+ def all!(finder_class, entity, params, *)
38
+ finder_class.new(entity: entity, params: params)
46
39
  end
47
- end
48
40
 
49
- def apply_id(params)
50
- return if params[:id].nil?
41
+ def single!(finder_class, entity, params, *)
42
+ apply_id(params)
43
+ if entity.nil?
44
+ finder_class.new(params: params).result.first
45
+ else
46
+ finder_class.new(entity: entity, params: params).result.first
47
+ end
48
+ end
51
49
 
52
- params[:id_eq] = params[:id]
50
+ def apply_id(params)
51
+ return if params[:id].nil?
52
+
53
+ params[:id_eq] = params[:id]
54
+ end
53
55
  end
54
56
  end
55
57
  end
@@ -14,12 +14,12 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "http://trailblazer.to"
15
15
  spec.license = "LGPL-3.0"
16
16
  spec.files = Dir.glob("lib/**/*")
17
- spec.files << ['trailblazer-finder.gemspec']
17
+ spec.files << ["trailblazer-finder.gemspec"]
18
18
  spec.test_files = spec.files.grep(%r{^(test)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "dry-types", ">= 1.0.0"
22
- spec.add_dependency "trailblazer-activity", ">= 0.10.0", "< 0.13.0"
22
+ spec.add_dependency "trailblazer-activity", ">= 0.13.0"
23
23
 
24
24
  spec.add_development_dependency "activerecord"
25
25
  spec.add_development_dependency "bundler"
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.80.1
4
+ version: 0.90.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-06-05 00:00:00.000000000 Z
13
+ date: 2022-06-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: dry-types
@@ -31,9 +31,6 @@ dependencies:
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - ">="
34
- - !ruby/object:Gem::Version
35
- version: 0.10.0
36
- - - "<"
37
34
  - !ruby/object:Gem::Version
38
35
  version: 0.13.0
39
36
  type: :runtime
@@ -41,9 +38,6 @@ dependencies:
41
38
  version_requirements: !ruby/object:Gem::Requirement
42
39
  requirements:
43
40
  - - ">="
44
- - !ruby/object:Gem::Version
45
- version: 0.10.0
46
- - - "<"
47
41
  - !ruby/object:Gem::Version
48
42
  version: 0.13.0
49
43
  - !ruby/object:Gem::Dependency
@@ -324,7 +318,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
324
318
  - !ruby/object:Gem::Version
325
319
  version: '0'
326
320
  requirements: []
327
- rubygems_version: 3.2.32
321
+ rubygems_version: 3.2.22
328
322
  signing_key:
329
323
  specification_version: 4
330
324
  summary: Trailblazer based finder objects. It is designed to be used on its own as