strum 0.0.30 → 0.0.31

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: 3cc3410ea8c7896616a0c101f919aec2d30679aef1059f71e9b2b7b22c132fd1
4
- data.tar.gz: e9d224772544d46180aaa1dd2fb382ee593d8a1af8103a51da5a498a72a43e7b
3
+ metadata.gz: 512a06663fe094ba5dfdbca09886dc8a4c910fe99d0e26a7fd0032feb2acbb10
4
+ data.tar.gz: bb2435ca4314b5f289fc108355ce5a414ce3f215e503406ccfdfeeb86fb734cb
5
5
  SHA512:
6
- metadata.gz: 84de9d475b3eaccf53b3568c01b0c869c70bbd02ccff42fe185b1fed5827d062563bd1d72695490b2aca70f8bb3ccce265343dbc90a8b0b0931ba2583dddb34a
7
- data.tar.gz: 37863393861879b8c6daed953346fced5057cb30971bc5d6344b0776db7baa55887ed4b8942bc84552ee4475fd0e285567890efcdf0ea48edfbca9aa3385f4ee
6
+ metadata.gz: 7619fe083dbdf6919e69af561fdbb3c0ddd32bc617c84bc3240220587078c56f841bdc289ec42f127fcbe80a989aa7fa4181155b752b28c30367bbe25967cca7
7
+ data.tar.gz: 92cfdba8069a14ff202856a597897eb99c385c19fcf59e473b10055f4b0379cda1871cdf6079affe5d9314b5e68b2b3ed54d5add50c8b9d79572a4d6b113929a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- strum (0.0.30)
4
+ strum (0.0.31)
5
5
  dry-inflector (~> 0.2.0)
6
6
  dry-matcher (~> 0.8.2)
7
7
  thor (~> 0.20)
@@ -12,7 +12,7 @@ module Strum
12
12
  end
13
13
 
14
14
  def audit
15
- clear_output!
15
+ # clear_output!
16
16
  add_error(:root, :data_and_errors_must_not_coexist) unless !root_data[:data] ^ !root_errors[:errors]
17
17
  end
18
18
 
@@ -12,9 +12,9 @@ module Strum
12
12
  output(serializer_class.new(input).serializable_hash)
13
13
  end
14
14
 
15
- define_method :audit do
16
- clear_output!
17
- end
15
+ # define_method :audit do
16
+ # clear_output!
17
+ # end
18
18
  end
19
19
  end
20
20
  end
@@ -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
@@ -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
- clear_output
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, :clear_output
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
- self.clear_output = true
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
- return outputs if output_clear?
142
- return outputs if payload.nil?
143
- return outputs unless payload.is_a?(Hash)
144
- return payload unless outputs.count.positive?
145
-
146
- outputs.each_with_object({}) do |(k, v), memo|
147
- memo[k] = v.is_a?(Hash) ? payload.merge(v) : v
148
- end
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?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Strum
4
- VERSION = "0.0.30"
4
+ VERSION = "0.0.31"
5
5
  end
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.30
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