simple_pipeline 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4a484ac10baf55839867a7e23333575331af1f2
4
- data.tar.gz: fa4e96d7ef40d54df3d08b274c167a2c21a1e57d
3
+ metadata.gz: 6e8e98e95e1f7dbcaa85aa81e4dffaec77bec74f
4
+ data.tar.gz: 8f2bc427a69debdb7f1f8a54ad8326a489ed8573
5
5
  SHA512:
6
- metadata.gz: be5125980ed3f7164f294d2db6a431c0f72769af801308ac95654d85e3fb76bcec280d0c092b30b88e6fc37cd3c52eafa0244a7246567a44bf0258dfc3f708aa
7
- data.tar.gz: bc1d2a74e196b4101067f409b9d7e0e69c9ea4941814f08fa69776b46ff170423f9b5e853e8cbe6f7b1298758b505c46b230aedf4677e21e6faa0b8ceeeec641
6
+ metadata.gz: 960562193e326990d0f585313f41fface19e7747c5c6c5c0da95fefb8b95d6f623b4748fca48cf8fd784a869a03fda85adc633ed7cd2f502d4931dc1e90633d8
7
+ data.tar.gz: 0a0ace2501e408a758045a399c2a869f681c6540c26fcae9d90ce701892c1708aedb9d702743c3cbf0d89542399a597d48c40260dd48d2aa07e90db8750dd9e7
data/README.md CHANGED
@@ -68,9 +68,34 @@ pipeline.add AlternativePipe.new, :process_method => :invoke # => throws Argumen
68
68
 
69
69
  The **payload** can be an Array, Hash, or any other Ruby object. Individual pipes have the responsibility to know what to do with the payload that is passed into the ```process``` method.
70
70
 
71
+ **SimplePipeline** supports an easy way to validate the contents of the current payload prior to the execution of a pipe. You can use the ```SimplePipeline::Validation``` mixin and specify validation rules via lambdas, which will be checked prior to processing the pipe. If any of the validation rules fail (i.e. the lambda returns false or raises an error), a ```SimplePipeline::Validation::Error``` will be raised.
72
+
73
+ ```ruby
74
+ class ValidatedPipe
75
+ include SimplePipeline::Validation
76
+
77
+ validate ->(x) { x[:a] } # x[:a] must exist
78
+ validate ->(x) { x[:b] == 1 } # x[:b] must be equal to 1
79
+ validate ->(x) { x[:c].nil? } # x[:c] must not exist
80
+ validate ->(x) { x[:d][:e] < 5 } # You can even do complex things like this
81
+
82
+ def process (payload)
83
+ # Do something
84
+ end
85
+ end
86
+
87
+ pipeline = SimplePipeline.new
88
+ pipeline.add ValidatedPipe.new
89
+
90
+ payload = {:a => some_value}
91
+
92
+ # Will throw a SimplePipeline::Validation::Error because not all validation rules are satisfied
93
+ pipeline.process payload
94
+ ```
95
+
71
96
  ## Timeout
72
97
 
73
- You can use the **SimplePipeline::Timeout** mixin to enforce a timeout value (in seconds) for a pipe. If the execution of the ```process``` method exceeds the specified timeout value, a ```Timeout::Error``` will be thrown.
98
+ You can use the ```SimplePipeline::Timeout``` mixin to enforce a timeout value (in seconds) for a pipe. If the execution of the ```process``` method exceeds the specified timeout value, a ```Timeout::Error``` will be thrown.
74
99
 
75
100
  ```ruby
76
101
  class TimeoutPipe
@@ -17,7 +17,11 @@ class SimplePipeline
17
17
 
18
18
  def validate (payload)
19
19
  self.class.class_variable_get(:@@validations).each do |validation_lambda|
20
- raise SimplePipeline::Validation::Error.new "#{self.class} - #{payload}" unless validation_lambda.call(payload)
20
+ begin
21
+ raise SimplePipeline::Validation::Error.new "#{self.class} - #{payload}" unless validation_lambda.call(payload)
22
+ rescue
23
+ raise SimplePipeline::Validation::Error.new "#{self.class} - #{payload}"
24
+ end
21
25
  end
22
26
  end
23
27
  end
@@ -1,3 +1,3 @@
1
1
  class SimplePipeline
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -42,8 +42,8 @@ class ValidationPipe
42
42
  include SimplePipeline::Validation
43
43
 
44
44
  validate ->(payload) { payload[:must_exist] }
45
- validate ->(payload) { payload[:must_be_false] == false }
46
45
  validate ->(payload) { payload[:a][:b] == 1 }
46
+ validate ->(payload) { payload[:must_be_false] == false }
47
47
 
48
48
  def process (payload)
49
49
  payload[:test_value] *= 10
@@ -149,7 +149,10 @@ describe SimplePipeline do
149
149
  pipeline = SimplePipeline.new
150
150
  pipeline.add ValidationPipe.new
151
151
 
152
- payload = {:test_value => 10}
152
+ payload = {
153
+ :test_value => 10,
154
+ :must_exist => "it does"
155
+ }
153
156
 
154
157
  expect {
155
158
  pipeline.process(payload)
@@ -157,7 +160,7 @@ describe SimplePipeline do
157
160
 
158
161
  payload = {
159
162
  :test_value => 10,
160
- :must_exist => "abc",
163
+ :must_exist => "it does",
161
164
  :must_be_false => false,
162
165
  :a => {:b => 1}
163
166
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_pipeline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Wong