metacrunch 4.1.1 → 4.2.0
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 +4 -4
 - data/Readme.md +5 -2
 - data/lib/metacrunch/job.rb +12 -13
 - data/lib/metacrunch/job/buffer.rb +1 -1
 - data/lib/metacrunch/version.rb +1 -1
 - 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: 1fc2560b2bb768757c384d71a806509d594e7610
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8cbb0e384582550d29f94daa2d7521942cbe14c9
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
             
            }
         
     | 
    
        data/lib/metacrunch/job.rb
    CHANGED
    
    | 
         @@ -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 
     | 
    
         
            -
                     
     | 
| 
       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
         
     | 
    
        data/lib/metacrunch/version.rb
    CHANGED