Skip to content

Commit

Permalink
Configurable namespace separator (#106)
Browse files Browse the repository at this point in the history
* make registry namespace separator configurable
* fix settings and reorg `Kiba::Extend` module so inter-app require statements can be removed
* require the show me extension so using this option does not fail!
* add doc section on using transforms in job definitions
  • Loading branch information
kspurgin authored Sep 22, 2022
1 parent d7e2fa1 commit 140e01a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 19 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ These changes are merged into the `main` branch but have not yet been tagged as

== Releases

=== 3.2.1 - 2022-09-21

==== Added
* Config setting to control string used as registry namespace separator

==== Bugfixes
* Require the kiba-common ShowMe extension so that option actually works when running jobs

==== Changed
* Refactoring `lib/kiba/extend.rb` so inter-application `require` statements can be removed

=== 3.2.0 - 2022-09-20

==== Added
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
kiba-extend (3.2.0)
kiba-extend (3.2.1)
activesupport (~> 6)
amazing_print (~> 1.4)
csv (~> 3)
Expand Down
26 changes: 24 additions & 2 deletions doc/common_patterns_tips_tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class Transformer
end
```

It can also be useful in other transforms as shown below:

It can also be used in order to compose additional behavior in another transform as shown below:

```
class Transformer
Expand All @@ -70,6 +69,29 @@ end

See the code for {Kiba::Extend::Transforms::Rename::Fields} for an example of embedding another transform to compose transformation logic.

## Using transforms in job definitions

The following code snippets are equivalent.

This one relies on the domain specific language (DSL) "magic" defined in kiba:

```
Kiba.job_segment do
transform Merge::ConstantValue, target: :data_source, value: 'source system'
end
```

This one uses plain Ruby to set up the transform class and calls its `:process` method on each row:

```
Kiba.job_segment do
xform = Merge::ConstantValue.new(target: :data_source, value: 'source system')
transform{ |row| xform.process(row) }
end
```

The second one might be useful in situations when you are trying to set things up more flexibly.

## Calling a job with parameters

No need to write repetitive jobs with the exact same logic to handle variable values that differ according to a pattern. See [File registry documentation on Hash creator](https://lyrasis.github.io/kiba-extend/file.file_registry_entry.html#hash-creator-example-since-2-7-2) for a full example of how to do this.
Expand Down
24 changes: 11 additions & 13 deletions lib/kiba/extend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
require 'xxhash'
require 'zeitwerk'

require 'kiba/extend/error'
require 'kiba/extend/registry/file_registry'
require 'kiba/extend/jobs'
require 'kiba/extend/jobs/job_segmenter'
require 'kiba/extend/destinations'
require 'kiba/extend/destinations/csv'

# The Kiba ETL framework for Ruby.
# `kiba-extend` extends only Kiba OSS. Kiba Pro features are not used.
#
Expand Down Expand Up @@ -70,9 +63,6 @@ def reload!
@loader.reload
end

# So we can call Kiba.job_segment
Kiba.extend(Kiba::Extend::Jobs::JobSegmenter)

# @return [Hash] default options used for CSV sources/destinations
setting :csvopts, default: { headers: true, header_converters: %i[symbol downcase] }, reader: true

Expand All @@ -91,14 +81,21 @@ def reload!

# @return [String] default string to be treated as though it were a null/empty value.
setting :nullvalue, default: '%NULLVALUE%', reader: true

# @return [String] used to join nested namespaces and registered keys in FileRegistry
# @example With namespace 'ns' and registered key 'foo'
# 'ns__foo'
# @example With parent namespace 'ns', child namespace 'child', and registered key 'foo'
# 'ns__child__foo'
setting :registry_namespace_separator, default: '__', reader: true

# @!method source
# Default source class for jobs. Must meet implementation criteria in [Kiba wiki](https://github.com/thbar/kiba/wiki/Implementing-ETL-sources)
setting :source, default: Kiba::Common::Sources::CSV, reader: true

# @!method destination
# Default destination class for jobs. Must meet implementation criteria in [Kiba wiki](https://github.com/thbar/kiba/wiki/Implementing-ETL-destinations)
setting :destination, default: Kiba::Extend::Destinations::CSV, reader: true
setting :destination, constructor: proc{ Kiba::Extend::Destinations::CSV }, reader: true

# @return [String] prefix for warnings from the ETL
setting :warning_label, default: 'KIBA WARNING', reader: true
Expand All @@ -107,8 +104,7 @@ def reload!
# [dry-container](https://dry-rb.org/gems/dry-container/main/) for registering and resolving
# jobs
setting :registry,
default: Kiba::Extend::Registry::FileRegistry,
constructor: proc { |value| value.new },
constructor: proc{ Kiba::Extend::Registry::FileRegistry.new },
reader: true

# @return [Symbol] the job definition module method expected to be present if you [define a registry
Expand Down Expand Up @@ -237,3 +233,5 @@ def warn_unnested(name, value)


Kiba::Extend.loader
# So we can call Kiba.job_segment
Kiba.extend(Kiba::Extend::Jobs::JobSegmenter)
3 changes: 2 additions & 1 deletion lib/kiba/extend/jobs/show_me_job.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'kiba/extend'
require 'kiba-common/dsl_extensions/show_me'

module Kiba
module Extend
module Jobs
Expand Down
2 changes: 1 addition & 1 deletion lib/kiba/extend/registry/file_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Registry
class FileRegistry
include Dry::Container::Mixin

config.namespace_separator = '__'
config.namespace_separator = Kiba::Extend.registry_namespace_separator

# Exception raised if the file key is not registered
class KeyNotRegisteredError < Kiba::Extend::Error
Expand Down
2 changes: 1 addition & 1 deletion lib/kiba/extend/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Kiba
module Extend
VERSION = '3.2.0'
VERSION = '3.2.1'
end
end

0 comments on commit 140e01a

Please sign in to comment.