kiba-common 0.6.0 → 0.7.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
  SHA256:
3
- metadata.gz: 1663d6106ac7cae429c6fba5a9bc3321222c957f44c21644eee77b73314f9e92
4
- data.tar.gz: 92dfe90ee5c9f725ffad8635e4397a8da08bd86b879c1f56530afb5b0c206a39
3
+ metadata.gz: 73129b07c0c847b9a1ed5b2a88e0fe3b9449200589fea6e0b88696959c86448f
4
+ data.tar.gz: 1a73e5414c054fbb233c92c5459087153a6ad413bfa194c192d8ea54cd4ee3ef
5
5
  SHA512:
6
- metadata.gz: 6f87775082169e7ce4f6bff67c4ba30c3504b5df81dc0c47a4f752ffdf96e6b752b7e9362e174f9b9ca4808ee0c2c042a0c93f3f2809ba734badcb212951e77e
7
- data.tar.gz: 47263dfa9ed01ac9ad266624478f9767c504be7e47b7546e9725e0c6f0652e75ab76a67ad08f70dca618f18142e47156f876efca732bc770315e734ba3a911a7
6
+ metadata.gz: f984de5843f926e3c153c381a1e05d171275fa185c3b0b2c7d855250b75c6ed85841ad78d87cb55b9cc4d6759e7d50c585765483ef27f0c3c64f80b8a739e957
7
+ data.tar.gz: 1e05cefc61c51f474f93b8f331e3d17a1de7c2ec3683212336796e3dcbc164bc9d5bc9049a8f255c25d237a8f8e38516d02db45f343a903d2bd76ad439515330
data/Changes.md CHANGED
@@ -1,6 +1,8 @@
1
1
  HEAD
2
2
  ----
3
3
 
4
+ - New: Kiba::Common::Transforms::SourceTransformAdapter let you transform rows into parameters for source instantiation.
5
+
4
6
  0.6.0
5
7
  -----
6
8
 
data/README.md CHANGED
@@ -38,6 +38,39 @@ You can pass a callable to make sure the evaluation will occur after your [pre-p
38
38
  source Kiba::Common::Sources::Enumerable, -> { Dir["input/*.json"] }
39
39
  ```
40
40
 
41
+ ### Kiba::Common::Transforms::SourceTransformAdapter
42
+
43
+ Let's say you have a source (e.g. `CSVSource`), which you would like to instantiate for each input row (e.g. a list of filenames).
44
+
45
+ Normally you'd have to bake file iteration right inside your source.
46
+
47
+ But since Kiba v2 introduction of `StreamingRunner`, it is possible for transforms to yield an arbitrary (potentially infinite) amount of rows.
48
+
49
+ Leveraging that possibility, you can use a `SourceTransformAdapter` to dynamically instantiate the source for each of your input rows.
50
+
51
+ This allows to mix-and-match components in a much more versatile & powerful way.
52
+
53
+ Requirements: Kiba v2 with `StreamingRunner` enabled.
54
+
55
+ Usage:
56
+
57
+ ```ruby
58
+ source Kiba::Common::Sources::Enumerable, -> { Dir["input/*.csv"] }
59
+
60
+ transform do |r|
61
+ # build up the args that you would normally pass to your source, e.g.
62
+ # source MyCSV, filename: 'file.csv'
63
+ # but instead, using the input as a parameter
64
+ [MyCSVSource, filename: r]
65
+ end
66
+
67
+ # this will instantiate one source per input row, yielding rows
68
+ # that your source would normally yield
69
+ transform Kiba::Common::Transforms::SourceTransformAdapter
70
+ ```
71
+
72
+ This can be used for a wide array of scenarios, including extracting data for N third-party accounts of a same system, with an array of API keys etc.
73
+
41
74
  ### Kiba::Common::Transforms::EnumerableExploder
42
75
 
43
76
  A transform calling `each` on input rows (assuming they are e.g. arrays of sub-rows) and yielding one output row per enumerated element.
data/kiba-common.gemspec CHANGED
@@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
17
17
  gem.add_development_dependency 'rake'
18
18
  gem.add_development_dependency 'minitest'
19
19
  gem.add_development_dependency 'awesome_print'
20
+ gem.add_development_dependency 'minitest-focus'
20
21
  end
@@ -0,0 +1,14 @@
1
+ module Kiba
2
+ module Common
3
+ module Transforms
4
+ class SourceTransformAdapter
5
+ def process(args)
6
+ args.shift.new(*args).each do |row|
7
+ yield(row)
8
+ end
9
+ nil
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  module Kiba
2
2
  module Common
3
- VERSION = '0.6.0'
3
+ VERSION = '0.7.0'
4
4
  end
5
5
  end
data/test/helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'minitest/autorun'
2
2
  require 'minitest/pride'
3
+ require 'minitest/focus'
3
4
 
4
5
  require 'kiba-common/sources/enumerable'
5
6
  require_relative 'support/assert_called'
@@ -0,0 +1,24 @@
1
+ require_relative 'helper'
2
+ require 'kiba-common/transforms/source_transform_adapter'
3
+
4
+ class TestSourceTransformAdapter < Minitest::Test
5
+ include Kiba::Common::Sources
6
+ include Kiba::DSLExtensions
7
+
8
+ def test_instantiation
9
+ rows = []
10
+ job = Kiba.parse do
11
+ extend Config
12
+ config :kiba, runner: Kiba::StreamingRunner
13
+
14
+ source Enumerable, [
15
+ [ Enumerable, (1..10) ],
16
+ [ Enumerable, (11..20) ]
17
+ ]
18
+ transform Kiba::Common::Transforms::SourceTransformAdapter
19
+ destination TestArrayDestination, rows
20
+ end
21
+ Kiba.run(job)
22
+ assert_equal (1..20).to_a, rows
23
+ end
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiba-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibaut Barrère
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-26 00:00:00.000000000 Z
11
+ date: 2018-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kiba
@@ -72,6 +72,20 @@ dependencies:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: minitest-focus
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
75
89
  description: Commonly used helpers for Kiba ETL
76
90
  email:
77
91
  - thibaut.barrere@gmail.com
@@ -92,6 +106,7 @@ files:
92
106
  - lib/kiba-common/dsl_extensions/show_me.rb
93
107
  - lib/kiba-common/sources/enumerable.rb
94
108
  - lib/kiba-common/transforms/enumerable_exploder.rb
109
+ - lib/kiba-common/transforms/source_transform_adapter.rb
95
110
  - lib/kiba-common/version.rb
96
111
  - test/helper.rb
97
112
  - test/support/assert_called.rb
@@ -101,6 +116,7 @@ files:
101
116
  - test/test_enumerable_source.rb
102
117
  - test/test_logger.rb
103
118
  - test/test_show_me.rb
119
+ - test/test_source_transform_adapter.rb
104
120
  homepage: https://github.com/thbar/kiba-common
105
121
  licenses:
106
122
  - LGPL-3.0
@@ -134,3 +150,4 @@ test_files:
134
150
  - test/test_enumerable_source.rb
135
151
  - test/test_logger.rb
136
152
  - test/test_show_me.rb
153
+ - test/test_source_transform_adapter.rb