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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/strum/pipe.rb +21 -7
- data/lib/strum/service.rb +4 -3
- data/lib/strum/templates/service_crud/%resources_name%/detect.rb.tt +30 -0
- data/lib/strum/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce5316836aff5a84ce5be1cb3af9445b5ebc80ba3c739626483929bb9ff7538d
|
4
|
+
data.tar.gz: ed3b056c7ab24e67efd4cae7e0ac5ddd31f981099c6911b9e11b659bd42af315
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 622ed6bc448d6f0124b09d159ae9801478a8ef526cbb56ec4f948647f38ea7fc54df863722e5512e0e2b2391db07239dd7ef93d282f994ecf8e7cc3acfe28dc9
|
7
|
+
data.tar.gz: db63d55f2a5ec36480e02f5dacf922f252f1a504a64af59c68fda4f500460436cc325702642a983c29e375d72a859c2b3aad1879edbf82257e2adf72a5a16586
|
data/Gemfile.lock
CHANGED
data/lib/strum/pipe.rb
CHANGED
@@ -17,7 +17,8 @@ module Strum
|
|
17
17
|
audit
|
18
18
|
yield(self) if valid? && block_given?
|
19
19
|
output(pipe_inputs)
|
20
|
-
|
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,
|
35
|
-
m.on(k) { |r|
|
35
|
+
service_handlers[:on].each do |k, _handler|
|
36
|
+
m.on(k) { |r| hook(k, r) }
|
36
37
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
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
|
data/lib/strum/service.rb
CHANGED
@@ -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
|
-
|
172
|
-
handler
|
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 -%>
|
data/lib/strum/version.rb
CHANGED
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.
|
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-
|
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
|