strum 0.0.30 → 0.0.31
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/strum/json_deserializer.rb +1 -1
- data/lib/strum/json_serializer.rb +3 -3
- data/lib/strum/pipe.rb +46 -0
- data/lib/strum/service.rb +20 -19
- data/lib/strum/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 512a06663fe094ba5dfdbca09886dc8a4c910fe99d0e26a7fd0032feb2acbb10
|
4
|
+
data.tar.gz: bb2435ca4314b5f289fc108355ce5a414ce3f215e503406ccfdfeeb86fb734cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7619fe083dbdf6919e69af561fdbb3c0ddd32bc617c84bc3240220587078c56f841bdc289ec42f127fcbe80a989aa7fa4181155b752b28c30367bbe25967cca7
|
7
|
+
data.tar.gz: 92cfdba8069a14ff202856a597897eb99c385c19fcf59e473b10055f4b0379cda1871cdf6079affe5d9314b5e68b2b3ed54d5add50c8b9d79572a4d6b113929a
|
data/Gemfile.lock
CHANGED
data/lib/strum/pipe.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Strum
|
4
|
+
class Pipe
|
5
|
+
include Strum::Service
|
6
|
+
|
7
|
+
def self.call(*units, input: {}, unit_input: {}, &block)
|
8
|
+
pipe_payload = if input.is_a?(Hash) && unit_input.is_a?(Hash)
|
9
|
+
unit_input.merge(input)
|
10
|
+
else
|
11
|
+
input
|
12
|
+
end
|
13
|
+
new(pipe_payload).execute(*units, input, unit_input, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute(*units, pipe_inputs, pipe_unit_inputs, &block)
|
17
|
+
audit
|
18
|
+
output(pipe_inputs)
|
19
|
+
while (unit = units.shift) && valid?
|
20
|
+
service, service_params = unit
|
21
|
+
service_params ||= {}
|
22
|
+
raise Strum::Error, "Unit options must be a Hash" unless service_params.is_a?(Hash)
|
23
|
+
|
24
|
+
service_options = service_params[:input] || {}
|
25
|
+
clean_output = service_params[:clean_output] || false
|
26
|
+
unit_payload = if !clean_output && service_options.is_a?(Hash) && pipe_unit_inputs.is_a?(Hash) && pipe_inputs.is_a?(Hash)
|
27
|
+
pipe_unit_inputs.merge(service_options).merge(output_value)
|
28
|
+
else
|
29
|
+
output_value
|
30
|
+
end
|
31
|
+
|
32
|
+
service.public_send(:call, unit_payload) do |m|
|
33
|
+
m.success do |result|
|
34
|
+
if !clean_output && result.is_a?(Hash) && output_value.is_a?(Hash)
|
35
|
+
output(output_value.merge(result))
|
36
|
+
else
|
37
|
+
output(result)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
m.failure { |errors| add_errors(errors) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
valid? ? valid_result(&block) : invalid_result(&block)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/strum/service.rb
CHANGED
@@ -39,7 +39,7 @@ module Strum
|
|
39
39
|
def initialize(payload)
|
40
40
|
self.strum_errors = {}
|
41
41
|
self.outputs = {}
|
42
|
-
self.clear_output = false
|
42
|
+
# self.clear_output = false
|
43
43
|
self.payload = payload
|
44
44
|
self.payload.freeze
|
45
45
|
self.input = self.payload.dup
|
@@ -59,13 +59,13 @@ module Strum
|
|
59
59
|
strum_errors
|
60
60
|
end
|
61
61
|
|
62
|
-
def output_clear?
|
63
|
-
|
64
|
-
end
|
62
|
+
# def output_clear?
|
63
|
+
# clear_output
|
64
|
+
# end
|
65
65
|
|
66
66
|
protected
|
67
67
|
|
68
|
-
attr_accessor :payload, :input, :strum_errors, :outputs
|
68
|
+
attr_accessor :payload, :input, :strum_errors, :outputs #, :clear_output
|
69
69
|
|
70
70
|
def call
|
71
71
|
raise Failure, "call method must be implemented"
|
@@ -117,9 +117,9 @@ module Strum
|
|
117
117
|
self.input = [*input]
|
118
118
|
end
|
119
119
|
|
120
|
-
def clear_output!
|
121
|
-
|
122
|
-
end
|
120
|
+
# def clear_output!
|
121
|
+
# self.clear_output = true
|
122
|
+
# end
|
123
123
|
|
124
124
|
private
|
125
125
|
|
@@ -130,23 +130,24 @@ module Strum
|
|
130
130
|
end
|
131
131
|
|
132
132
|
def valid_result(&block)
|
133
|
-
result_outputs = rich_outputs
|
133
|
+
# result_outputs = rich_outputs
|
134
|
+
result_outputs = outputs
|
134
135
|
return result_outputs[:default] || result_outputs unless block_given?
|
135
136
|
return StrumMatcher.call([true, result_outputs[:default]], &block) if result_outputs[:default]
|
136
137
|
|
137
138
|
StrumMatcher.call([true, *result_outputs.keys, result_outputs], &block)
|
138
139
|
end
|
139
140
|
|
140
|
-
def rich_outputs
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
end
|
141
|
+
# def rich_outputs
|
142
|
+
# return outputs if output_clear?
|
143
|
+
# return outputs if payload.nil?
|
144
|
+
# return outputs unless payload.is_a?(Hash)
|
145
|
+
# return payload unless outputs.count.positive?
|
146
|
+
#
|
147
|
+
# outputs.each_with_object({}) do |(k, v), memo|
|
148
|
+
# memo[k] = v.is_a?(Hash) ? payload.merge(v) : v
|
149
|
+
# end
|
150
|
+
# end
|
150
151
|
|
151
152
|
def invalid_result(&block)
|
152
153
|
return nil unless block_given?
|
data/lib/strum/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.31
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Serhiy Nazarov
|
@@ -158,6 +158,7 @@ files:
|
|
158
158
|
- lib/strum/commands/resource/service.rb
|
159
159
|
- lib/strum/json_deserializer.rb
|
160
160
|
- lib/strum/json_serializer.rb
|
161
|
+
- lib/strum/pipe.rb
|
161
162
|
- lib/strum/serializer_name.rb
|
162
163
|
- lib/strum/service.rb
|
163
164
|
- lib/strum/sub_command_base.rb
|