strum 0.0.55 → 0.0.56

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: 442b975d036c77d40e013582ed6c45f27ed77b1ccd01975dbec3aa89d28c2115
4
- data.tar.gz: 6bc0253b8e8b8ab605129e3b34486ca54ba36378528e894d6481b08349af4e38
3
+ metadata.gz: ce5316836aff5a84ce5be1cb3af9445b5ebc80ba3c739626483929bb9ff7538d
4
+ data.tar.gz: ed3b056c7ab24e67efd4cae7e0ac5ddd31f981099c6911b9e11b659bd42af315
5
5
  SHA512:
6
- metadata.gz: 00f7d03f21b91ed6ae174202a7336dacb6c2cef4f2bba369fed16db5812e3188e46938cb0792c170cfe218b4d9cb8df5844109912d000ee89b11f2aad9d5ee01
7
- data.tar.gz: 3eee0dc77298cd2e6e2138932de91bde002208d6709d4128bdf26a00f872019f0ea58fac0271891e609d78908d12857f96cdb53113305f5b49a1fbc6fbdd9173
6
+ metadata.gz: 622ed6bc448d6f0124b09d159ae9801478a8ef526cbb56ec4f948647f38ea7fc54df863722e5512e0e2b2391db07239dd7ef93d282f994ecf8e7cc3acfe28dc9
7
+ data.tar.gz: db63d55f2a5ec36480e02f5dacf922f252f1a504a64af59c68fda4f500460436cc325702642a983c29e375d72a859c2b3aad1879edbf82257e2adf72a5a16586
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- strum (0.0.55)
4
+ strum (0.0.56)
5
5
  dry-inflector (~> 0.2.0)
6
6
  dry-struct (~> 1.2)
7
7
  json-schema (~> 2.8.1)
@@ -17,7 +17,8 @@ module Strum
17
17
  audit
18
18
  yield(self) if valid? && block_given?
19
19
  output(pipe_inputs)
20
- while (unit = units.shift) && valid?
20
+ continue = true
21
+ while (unit = units.shift) && valid? && continue
21
22
  service, service_params = unit
22
23
  service_params ||= {}
23
24
  raise Strum::Error, "Unit options must be a Hash" unless service_params.is_a?(Hash)
@@ -31,16 +32,29 @@ module Strum
31
32
  end
32
33
 
33
34
  service.public_send(:call, unit_payload) do |m|
34
- service_handlers[:on].each do |k, proc|
35
- m.on(k) { |r| proc.call(r) }
35
+ service_handlers[:on].each do |k, _handler|
36
+ m.on(k) { |r| hook(k, r) }
36
37
  end
37
- m.success do |result|
38
- if !clean_output && result.is_a?(Hash) && output_value.is_a?(Hash)
39
- output(output_value.merge(result))
38
+
39
+ service_handlers[:success].each do |k, _handler|
40
+ if k
41
+ m.success(k) do |result|
42
+ output(k, result)
43
+ continue = false
44
+ end
40
45
  else
41
- output(result)
46
+ m.success do |result|
47
+ if result.nil?
48
+ # do nothing if service hasn't result
49
+ elsif !clean_output && result.is_a?(Hash) && output_value.is_a?(Hash)
50
+ output(output_value.merge(result))
51
+ else
52
+ output(result)
53
+ end
54
+ end
42
55
  end
43
56
  end
57
+
44
58
  m.failure { |errors| add_errors(errors) }
45
59
  end
46
60
  end
@@ -160,7 +160,7 @@ module Strum
160
160
  end
161
161
 
162
162
  private
163
-
163
+
164
164
  def key_to_sym(key)
165
165
  key.to_sym
166
166
  rescue StandardError
@@ -168,8 +168,9 @@ module Strum
168
168
  end
169
169
 
170
170
  def valid_result
171
- handler = service_handlers[:success][((outputs.keys << nil) & service_handlers[:success].keys).first]
172
- handler.is_a?(Proc) ? handler.call(outputs[:default] || outputs) : outputs[:default] || outputs
171
+ handler_key = ((outputs.keys << nil) & service_handlers[:success].keys).first
172
+ handler = service_handlers[:success][handler_key]
173
+ handler.is_a?(Proc) ? handler.call(outputs[handler_key] || outputs[:default]) : outputs[handler_key] || outputs[:default]
173
174
  end
174
175
 
175
176
  def invalid_result
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ <%- namespace_names.each_with_index do |c,i| -%>
4
+ <%= ' ' * i %>module <%= c %>
5
+ <%- end -%>
6
+ <%= ident %>module <%= resources_class_name %>
7
+ <%= ident %> # Strum service
8
+ <%= ident %> # You service description here...
9
+ <%= ident %> class Find
10
+ <%= ident %> include Strum::Service
11
+
12
+ <%= ident %> def call
13
+ <%= ident %> if (<%= resources_name %> = <%= resources_class_name %>::Search(input)).count.eql?(1)
14
+ <%= ident %> output(resources_name: <%= resources_name %>.first)
15
+ <%= ident %> elsif <%= resources_name %>.count > 1
16
+ <%= ident %> add_error(:<%= resource_name %>, :criteria_wrong)
17
+ <%= ident %> else
18
+ <%= ident %> add_error(:<%= resource_name %>, :not_found)
19
+ <%= ident %> end
20
+ <%= ident %> end
21
+
22
+ <%= ident %> def audit
23
+ <%= ident %> @input = @input.slice(:id)
24
+ <%= ident %> required(:id)
25
+ <%= ident %> end
26
+ <%= ident %> end
27
+ <%= ident %>end
28
+ <%- (namespace_names.size - 1).downto(0) do |i| -%>
29
+ <%= ' ' * i %>end
30
+ <%- end -%>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Strum
4
- VERSION = "0.0.55"
4
+ VERSION = "0.0.56"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.55
4
+ version: 0.0.56
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serhiy Nazarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-07 00:00:00.000000000 Z
11
+ date: 2020-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -236,6 +236,7 @@ files:
236
236
  - lib/strum/templates/service/%resource_filename%.rb.tt
237
237
  - lib/strum/templates/service_crud/%resources_name%/create.rb.tt
238
238
  - lib/strum/templates/service_crud/%resources_name%/delete.rb.tt
239
+ - lib/strum/templates/service_crud/%resources_name%/detect.rb.tt
239
240
  - lib/strum/templates/service_crud/%resources_name%/find.rb.tt
240
241
  - lib/strum/templates/service_crud/%resources_name%/search.rb.tt
241
242
  - lib/strum/templates/service_crud/%resources_name%/update.rb.tt