-
-
Notifications
You must be signed in to change notification settings - Fork 87
How to extend the Kiba DSL
Thibaut Barrère edited this page Feb 10, 2020
·
1 revision
The default Kiba DSL only includes a very limited set of DSL keywords, namely:
source
transform
destination
pre_process
post_process
It can be useful, though, to create new keywords for scenarios which involve a lot of reuse.
Here is how to create modular blocks of DSL reuse, in a way that restricts conflicts & pollution:
module DSLExtensions
module FieldTransforms
def set_if_blank(field, default_value)
transform do |row|
if row.fetch(field).blank?
row.merge(field => default_value)
else
row
end
end
end
def copy_field(from:, to:)
transform do |row|
row.merge(from => row.fetch(to))
end
end
end
end
You can then use this with:
Kiba.parse do
extend DSLExtensions::FieldTransforms
source ...
copy_field from: 'id_du_client', to: :client_id
set_if_blank :locale, 'en-US'
destination ...
end
See examples of this use of pattern:
- Kiba Common: https://github.com/thbar/kiba-common/tree/master/lib/kiba-common/dsl_extensions (logger & show_me extensions)
- Kiba: https://github.com/thbar/kiba/blob/master/lib/kiba/dsl_extensions/config.rb (more advanced)
Home | Core Concepts | Defining jobs | Running jobs | Writing sources | Writing transforms | Writing destinations | Implementation Guidelines | Kiba Pro
This wiki is tracked by git and publicly editable. You are welcome to fix errors and typos. Any defacing or vandalism of content will result in your changes being reverted and you being blocked.