diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 1649e17ab..b98e8e13f 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 488efc73c..0b087d6d7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/doc/common_patterns_tips_tricks.md b/doc/common_patterns_tips_tricks.md index 8fae63477..e70062238 100644 --- a/doc/common_patterns_tips_tricks.md +++ b/doc/common_patterns_tips_tricks.md @@ -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 @@ -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. diff --git a/lib/kiba/extend.rb b/lib/kiba/extend.rb index 4836a1dab..2b6255363 100644 --- a/lib/kiba/extend.rb +++ b/lib/kiba/extend.rb @@ -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. # @@ -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 @@ -91,6 +81,13 @@ 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) @@ -98,7 +95,7 @@ def reload! # @!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 @@ -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 @@ -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) diff --git a/lib/kiba/extend/jobs/show_me_job.rb b/lib/kiba/extend/jobs/show_me_job.rb index 5adb971d8..d908b3098 100644 --- a/lib/kiba/extend/jobs/show_me_job.rb +++ b/lib/kiba/extend/jobs/show_me_job.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true -require 'kiba/extend' +require 'kiba-common/dsl_extensions/show_me' + module Kiba module Extend module Jobs diff --git a/lib/kiba/extend/registry/file_registry.rb b/lib/kiba/extend/registry/file_registry.rb index 9ba92b33a..aeb410463 100644 --- a/lib/kiba/extend/registry/file_registry.rb +++ b/lib/kiba/extend/registry/file_registry.rb @@ -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 diff --git a/lib/kiba/extend/version.rb b/lib/kiba/extend/version.rb index 81a4a7faa..6010da2b9 100644 --- a/lib/kiba/extend/version.rb +++ b/lib/kiba/extend/version.rb @@ -2,6 +2,6 @@ module Kiba module Extend - VERSION = '3.2.0' + VERSION = '3.2.1' end end