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 +4 -4
- data/README.md +26 -1
- data/lib/simple_pipeline/validation.rb +5 -1
- data/lib/simple_pipeline/version.rb +1 -1
- data/spec/simple_pipeline_spec.rb +6 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e8e98e95e1f7dbcaa85aa81e4dffaec77bec74f
|
4
|
+
data.tar.gz: 8f2bc427a69debdb7f1f8a54ad8326a489ed8573
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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
|
@@ -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 = {
|
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 => "
|
163
|
+
:must_exist => "it does",
|
161
164
|
:must_be_false => false,
|
162
165
|
:a => {:b => 1}
|
163
166
|
}
|