metacrunch 4.1.1 → 4.2.0

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: c57943da0f6fc1236b58f06326223070fd1cf20d
4
- data.tar.gz: 0a905216b6a340aed1fe95425711877cfd3384ea
3
+ metadata.gz: 1fc2560b2bb768757c384d71a806509d594e7610
4
+ data.tar.gz: 8cbb0e384582550d29f94daa2d7521942cbe14c9
5
5
  SHA512:
6
- metadata.gz: '086cafcc6d00451da522d74a57379fa9be25538b77f4733be5ee3a1923ea38933394e00dd111fdbdfba43055989db2ba0e2879b5145ae3aa7fb8060e8f6295db'
7
- data.tar.gz: 19c2bfaf59bd1e695aa5569f12037448ce19a52cde3c93a62b9afa99b3c4269fc5efba1042b7321d255c099ae8b44cff269d25ad9b14b44928f9983badfae61b
6
+ metadata.gz: eaf6d9b6b72b7cadc92dae0d4d9e1204f6d43fe909f2f5f60bda85ad0407aa6fffe567a119361d3cef3fa15ed2d83ca5abc44d314eafc3f59b7b936c49a07ab5
7
+ data.tar.gz: 0204e2e3284a53c007ea086b883ff52fbb87e0731616fe83c1c4d636134985506c39d885ec8ff4bc4cc8708e3a51d02c27e28fe79b732798f7f3bfc24905ac6d
data/Readme.md CHANGED
@@ -72,7 +72,10 @@ To process, transform or manipulate data use the `#transformation` hook. A trans
72
72
 
73
73
  The current data object (the last object yielded by the source) will be passed to the first transformation as a parameter. The return value of a transformation will then be passed to the next transformation and so on.
74
74
 
75
- If you return `nil` the current data object will be dismissed and the next transformation won't be called.
75
+ There are two exceptions to that rule.
76
+
77
+ * If you return `nil` the current data object will be dismissed and the next transformation won't be called.
78
+ * If you return an `Enumerator` the object will be expanded and the following transformations will be called with each element of the `Enumerator`.
76
79
 
77
80
  ```ruby
78
81
  # File: my_etl_job.metacrunch
@@ -119,7 +122,7 @@ transformation ->(bulk) {
119
122
 
120
123
  # A buffer that uses a Proc
121
124
  transformation ->(bulk) {
122
- # ...
125
+ # Called when the buffer `Proc` returns `true`
123
126
  }, buffer: -> {
124
127
  true if some_condition
125
128
  }
@@ -83,12 +83,12 @@ class Metacrunch::Job # http://valve.github.io/blog/2013/10/26/constant-resoluti
83
83
  if source
84
84
  # Run transformation for each data object available in source
85
85
  source.each do |data|
86
- data = run_transformations(data)
86
+ data = run_transformations(transformations, data)
87
87
  write_destination(data)
88
88
  end
89
89
 
90
90
  # Run all transformations a last time to flush existing buffers
91
- data = run_transformations(nil, flush_buffers: true)
91
+ data = run_transformations(transformations, nil, flush_buffers: true)
92
92
  write_destination(data)
93
93
 
94
94
  # Close destination
@@ -123,19 +123,18 @@ private
123
123
  post_process.call if post_process
124
124
  end
125
125
 
126
- def run_transformations(data, flush_buffers: false)
127
- transformations.each do |transformation|
126
+ def run_transformations(transformations, data, flush_buffers: false)
127
+ transformations.each.with_index do |transformation, i|
128
128
  if transformation.is_a?(Buffer)
129
- buffer = transformation
130
-
131
- if data
132
- data = buffer.buffer(data)
133
- data = buffer.flush if flush_buffers
134
- else
135
- data = buffer.flush
136
- end
129
+ data = transformation.buffer(data) if data
130
+ data = transformation.flush if flush_buffers
137
131
  else
138
132
  data = transformation.call(data) if data
133
+
134
+ if data&.is_a?(Enumerator)
135
+ data.each { |d| run_transformations(transformations.slice(i+1..-1), d, flush_buffers: flush_buffers) }
136
+ data = nil
137
+ end
139
138
  end
140
139
  end
141
140
 
@@ -143,7 +142,7 @@ private
143
142
  end
144
143
 
145
144
  def write_destination(data)
146
- destination.write(data) if destination && data
145
+ destination.write(data) if destination && data.present?
147
146
  end
148
147
 
149
148
  end
@@ -22,7 +22,7 @@ module Metacrunch
22
22
  end
23
23
 
24
24
  def flush
25
- @buffer
25
+ @buffer.presence
26
26
  ensure
27
27
  @buffer = []
28
28
  end
@@ -1,3 +1,3 @@
1
1
  module Metacrunch
2
- VERSION = "4.1.1"
2
+ VERSION = "4.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metacrunch
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.1
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - René Sprotte