kiba-common 0.9.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7823ab2b0363a8fd2a2dd69bd2c70fd75db837ab4a583464e46a330f3c489cbf
4
- data.tar.gz: 2e61b3b7aaacfb930bd62f3a5714a86b511f35d4de8ccda71dbab3bc15b747eb
3
+ metadata.gz: f653d17ff9010ff236b2b77be61db1f3e42f6e2dd4708d39d20eb20e042b9c41
4
+ data.tar.gz: d441ae590b81d1a3eaa713517263d45c50da5d3cf402621774ee8488adcde5b3
5
5
  SHA512:
6
- metadata.gz: cdd431a4c090e7e59aea5dfc4ed3320f5643afeeaa729969a960bb8cb9ee35a1a0f77788ee9e1036f386f8cce064ae946330dc0592bce35a9388358bf6dcb39e
7
- data.tar.gz: 93900ad025f97f0463f1acaf95bf003ac94cf0a0d49230c4b49c9d77efe23b0dd86e329f92593c970b777e19e98fe563f54028934495d533c3cef453fc33bc4d
6
+ metadata.gz: f96da2fed54240556aafcb2877c8fd1a23c8c062c92d06cfc4ce4219d64f4131955775e64bd1c98985aca39d92b035645d8139edfead76603ea60daeff516836
7
+ data.tar.gz: 1fd250ae471dc68cc2d8322434d4d6f75ee661791f1e552604651d808b817b0874ffa788b0c8e70508f61ea90b49626ebe240db6807ac1f4961bf57e95a95719
@@ -1,11 +1,15 @@
1
1
  language: ruby
2
- before_install:
3
- # https://stackoverflow.com/a/47972768
4
- - gem update --system
5
- - gem update bundler
6
2
  rvm:
7
- - ruby-head
8
- - 2.5.0
9
- - 2.4.3
10
- - 2.3.6
11
- - jruby-9.1.15.0
3
+ # see https://www.ruby-lang.org/en/downloads/branches/
4
+ # NOTE: temporarily disabled due to failures to be investigated - see #26
5
+ # - ruby-head
6
+ - 2.7
7
+ - 2.6
8
+ - 2.5
9
+ - 2.4
10
+ # NOTE: EOL since 2019-03-31
11
+ - 2.3
12
+ # see https://www.jruby.org/download
13
+ - jruby-9.1
14
+ - jruby-9.2
15
+ - truffleruby
data/Changes.md CHANGED
@@ -1,6 +1,12 @@
1
1
  HEAD
2
2
  ----
3
3
 
4
+ 1.0.0
5
+ -----
6
+
7
+ - Kiba ETL v3 compatibility
8
+ - New: Kiba::Common::Destinations::Lambda lets you write block-form destinations (handy for one-off scripts).
9
+
4
10
  0.9.0
5
11
  -----
6
12
 
data/README.md CHANGED
@@ -148,6 +148,14 @@ source Kiba::Common::Sources::CSV, filename: 'input.csv',
148
148
  csv_options: { headers: true, header_converters: :symbol }
149
149
  ```
150
150
 
151
+ Note that the emitted rows are instances of [`CSV::Row`](http://ruby-doc.org/stdlib-2.5.3/libdoc/csv/rdoc/CSV/Row.html), part `Array` and part `Hash`, which retain order of fields and allow duplicates (unlike a regular `Hash`).
152
+
153
+ If the rest of your pipeline expects `Hash` rows (like for instance `Kiba::Common::Destinations::CSV`), you'll want to transform the rows to `Hash` instances yourself using [`to_hash`](http://ruby-doc.org/stdlib-2.5.3/libdoc/csv/rdoc/CSV/Row.html#method-i-to_hash). This will "collapse the row into a simple Hash. Be warned that this discards field order and clobbers duplicate fields."
154
+
155
+ ```ruby
156
+ transform { |r| r.to_hash }
157
+ ```
158
+
151
159
  #### Handling multiple input CSV files
152
160
 
153
161
  You can process multiple files by chaining the various components available in Kiba Common (see `test/test_integration#test_multiple_csv_inputs` for an actual demo):
@@ -217,6 +225,30 @@ destination Kiba::Common::Destinations::CSV,
217
225
  headers: [:field, :other_field]
218
226
  ```
219
227
 
228
+ ### Kiba::Common::Destinations::Lambda
229
+
230
+ At times, it can be convenient to use a block form for a destination (pretty much like Kiba's built-in "block transform"), especially for one-off scripts.
231
+
232
+ The Lambda destination is there for that purpose.
233
+
234
+ Example use:
235
+
236
+ ```ruby
237
+ require 'kiba-common/destinations/lambda'
238
+
239
+ destination Kiba::Common::Destinations::Lambda,
240
+ # called at destination instantiation time (once)
241
+ on_init: -> { ... },
242
+ # called for each row
243
+ on_write: -> (row) { ... },
244
+ # called after all the rows have been written
245
+ on_close: -> { ... }
246
+ ```
247
+
248
+ Each "callback" (e.g. `on_init`) is optional.
249
+
250
+ The callback code can refer to scope variables or instance variables you may have declared above.
251
+
220
252
  ### Kiba::Common::DSLExtensions::Logger
221
253
 
222
254
  A simple logging facility.
@@ -12,8 +12,12 @@ Gem::Specification.new do |gem|
12
12
  gem.name = 'kiba-common'
13
13
  gem.require_paths = ['lib']
14
14
  gem.version = Kiba::Common::VERSION
15
+ gem.metadata = {
16
+ 'source_code_uri' => 'https://github.com/thbar/kiba-common',
17
+ 'documentation_uri' => 'https://github.com/thbar/kiba-common/blob/master/README.md',
18
+ }
15
19
 
16
- gem.add_dependency 'kiba', '>= 1.0.0', '< 3'
20
+ gem.add_dependency 'kiba', '>= 1.0.0', '< 4'
17
21
  gem.add_development_dependency 'rake'
18
22
  gem.add_development_dependency 'minitest'
19
23
  gem.add_development_dependency 'awesome_print'
@@ -0,0 +1,23 @@
1
+ module Kiba
2
+ module Common
3
+ module Destinations
4
+ class Lambda
5
+ attr_reader :on_write, :on_close
6
+
7
+ def initialize(on_init: nil, on_write: nil, on_close: nil)
8
+ @on_write = on_write
9
+ @on_close = on_close
10
+ on_init&.call
11
+ end
12
+
13
+ def write(row)
14
+ on_write&.call(row)
15
+ end
16
+
17
+ def close
18
+ on_close&.call
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Kiba
2
2
  module Common
3
- VERSION = '0.9.0'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -25,7 +25,7 @@ class TestIntegration < Minitest::Test
25
25
  config :kiba, runner: Kiba::StreamingRunner
26
26
 
27
27
  # create one row per input file
28
- source Kiba::Common::Sources::Enumerable, -> { Dir[File.join(dir, '*.csv')] }
28
+ source Kiba::Common::Sources::Enumerable, -> { Dir[File.join(dir, '*.csv')].sort }
29
29
 
30
30
  # out of that row, create configuration for a CSV source
31
31
  transform do |r|
@@ -0,0 +1,22 @@
1
+ require_relative 'helper'
2
+ require 'kiba'
3
+ require 'kiba-common/destinations/lambda'
4
+
5
+ class TestLambdaDestination < MiniTest::Test
6
+ def test_lambda
7
+ accumulator = []
8
+ on_init_called = false
9
+ on_close_called = false
10
+ job = Kiba.parse do
11
+ source Kiba::Common::Sources::Enumerable, ['one', 'two']
12
+ destination Kiba::Common::Destinations::Lambda,
13
+ on_init: -> { on_init_called = true },
14
+ on_write: -> (r) { accumulator << r },
15
+ on_close: -> { on_close_called = true }
16
+ end
17
+ Kiba.run(job)
18
+ assert_equal ['one', 'two'], accumulator
19
+ assert_equal true, on_init_called
20
+ assert_equal true, on_close_called
21
+ end
22
+ 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.9.0
4
+ version: 1.0.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-09-05 00:00:00.000000000 Z
11
+ date: 2020-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kiba
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 1.0.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '3'
22
+ version: '4'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 1.0.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '3'
32
+ version: '4'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rake
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -102,6 +102,7 @@ files:
102
102
  - Rakefile
103
103
  - kiba-common.gemspec
104
104
  - lib/kiba-common/destinations/csv.rb
105
+ - lib/kiba-common/destinations/lambda.rb
105
106
  - lib/kiba-common/dsl_extensions/logger.rb
106
107
  - lib/kiba-common/dsl_extensions/show_me.rb
107
108
  - lib/kiba-common/sources/csv.rb
@@ -117,13 +118,16 @@ files:
117
118
  - test/test_enumerable_exploder_transform.rb
118
119
  - test/test_enumerable_source.rb
119
120
  - test/test_integration.rb
121
+ - test/test_lambda_destination.rb
120
122
  - test/test_logger.rb
121
123
  - test/test_show_me.rb
122
124
  - test/test_source_transform_adapter.rb
123
125
  homepage: https://github.com/thbar/kiba-common
124
126
  licenses:
125
127
  - LGPL-3.0
126
- metadata: {}
128
+ metadata:
129
+ source_code_uri: https://github.com/thbar/kiba-common
130
+ documentation_uri: https://github.com/thbar/kiba-common/blob/master/README.md
127
131
  post_install_message:
128
132
  rdoc_options: []
129
133
  require_paths:
@@ -139,8 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
143
  - !ruby/object:Gem::Version
140
144
  version: '0'
141
145
  requirements: []
142
- rubyforge_project:
143
- rubygems_version: 2.7.6
146
+ rubygems_version: 3.0.3
144
147
  signing_key:
145
148
  specification_version: 4
146
149
  summary: Commonly used helpers for Kiba ETL
@@ -153,6 +156,7 @@ test_files:
153
156
  - test/test_enumerable_exploder_transform.rb
154
157
  - test/test_enumerable_source.rb
155
158
  - test/test_integration.rb
159
+ - test/test_lambda_destination.rb
156
160
  - test/test_logger.rb
157
161
  - test/test_show_me.rb
158
162
  - test/test_source_transform_adapter.rb