Skip to content

Commit cd54d7c

Browse files
committed
docs: Update registry entry reference page
1 parent 335494c commit cd54d7c

1 file changed

Lines changed: 51 additions & 37 deletions

File tree

doc/file_registry_entry.md

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ The allowable Hash keys, expected Hash value formats, and expectations about the
4040
**NOTE:** (Since 3.0.0) For all keys besides `:dest_special_opts`, you may pass a Proc that returns the expected value format when called. For `:dest_special_opts`, you may pass Procs as individual values within the option Hash. This can be useful if you need to pass in a value that depends on other project config that may not be loaded/set up when registry is initially populated. A publicly available example is in `kiba-tms` which [sets destination initial headers](https://github.com/lyrasis/kiba-tms/blob/eb8f222f0dc753921e58d136cd15e5eab7472c60/lib/kiba/tms/table/prep/destination_options.rb#L32-L34) [based on the preferred name field for a given TMS client project, and whether they want to include "flipped" form as variant terms](https://github.com/lyrasis/kiba-tms/blob/eb8f222f0dc753921e58d136cd15e5eab7472c60/lib/kiba/tms/constituents.rb#L140-L148).
4141

4242
### `:path`
43-
[String] full or expandable relative path to the expected location of the file
43+
[String] full path or expandable relative path to the expected location of the file associated with the registry entry. If it is a supplied entry, the file must be present at this location. If it is a job entry, this is the location where the output of the job is written.
4444

4545
* default: `nil`
46-
* required if either `:src_class` or `:dest_class` requires a path
46+
* A path String value is required if either `:src_class` or `:dest_class` requires a path
4747

4848
### `:src_class`
49-
[Class] the Ruby class used to read in data. This class must be defined in the `Sources` namespace or equivalent. Example: you should never use {Kiba::Extend::Destinations::CSV} as a `src_class`value.
49+
[Class] the Ruby class used to read in data. This class must be defined in the `Sources` namespace or equivalent. That is, {Kiba::Extend::Destinations::CSV} will not work as a `src_class` value.
5050

5151
* required, but default supplied if not given
52-
* default: value of {Kiba::Extend.source} (`Kiba::Extend::Sources::CSV` unless overridden by your ETL app)
52+
* default: value of {Kiba::Extend.source} (This will be `Kiba::Extend::Sources::CSV` unless overridden by your ETL app)
5353

5454
### `:src_opt`
5555
[Hash] file options used when reading in source
@@ -62,10 +62,10 @@ The allowable Hash keys, expected Hash value formats, and expectations about the
6262
* A hash of keyword parameters defined for [MARC::Reader](https://github.com/ruby-marc/ruby-marc/blob/main/lib/marc/reader.rb) can be entered, for example: `{external_encoding: "MARC-8", internal_encoding: "UTF-16LE"}`
6363

6464
### `:dest_class`
65-
[Class] the Ruby class used to write out the data. This class must be defined in the `Destinations` namespace or equivalent. Example: you should never use `Kiba::Extend::Sources::CSV` as a `:dest_class` value.
65+
[Class] the Ruby class used to write out the data. This class must be defined in the `Destinations` namespace or equivalent. That is, `Kiba::Extend::Sources::CSV` will not work as a `:dest_class` value.
6666

6767
* required, but default supplied if not given
68-
* default: value of {Kiba::Extend.destination} ({Kiba::Extend::Destinations::CSV} unless overridden by your ETL app)
68+
* default: value of {Kiba::Extend.destination} (This will be {Kiba::Extend::Destinations::CSV} unless overridden by your ETL app)
6969

7070
### `:dest_opt`
7171
[Hash] file options used when writing data
@@ -82,7 +82,7 @@ The allowable Hash keys, expected Hash value formats, and expectations about the
8282
* optional
8383
* Only the following destination classes support extra options. If you provide unsupported extra options, they will not be sent through to the destination class, and you will receive a warning in STDOUT.
8484
* {Kiba::Extend::Destinations::CSV} (`initial_headers`)
85-
* {Kiba::Extend::Destinations::Marc} (`allow_oversized`)
85+
* {Kiba::Extend::Destinations::Marc} (`allow_oversized`) - Sets the `MARC::Writer` created by the destination to allow oversized records. See [`MARC::Writer` code](https://github.com/ruby-marc/ruby-marc/blob/main/lib/marc/writer.rb) for explanation.
8686

8787
Examples:
8888

@@ -103,19 +103,19 @@ reghash = {
103103
~~~
104104

105105
### `:creator`
106-
[Method, Module, Hash] Ruby method that generates this file
106+
[Method, Module, Hash] to run the job and create the expected output
107107

108108
* Used to run ETL jobs to create necessary files, if said files do not exist
109-
* Not required at all if file is supplied
110-
* If the method that runs the job is a module instance method named `job`, creator value can just be the `Module` containing the `:job` method
111-
* Otherwise, the creator value must be a `Method` (Pattern: `Class::Or::Module::ConstantName.method(:name_of_method)`)
112-
* Sometimes you may need to call a job with arguments. This may be particularly useful if the same job logic can be reused many times with slightly different parameters. In this case creator may be a Hash with `callee` and `args` keys
109+
* Not required if file is supplied
110+
* When to give a `Method`, `Module`, or `Hash` as `:creator` is described below.
113111

114-
NOTE: The default value for {Kiba::Extend.default_job_method_name} is `:job`. You can override this in your project's base file as follows (since 2.7.2):
112+
#### `Module` creator example (since 2.7.2)
113+
114+
The default value for {Kiba::Extend.default_job_method_name} is `:job`. You can override this in your project's base file as follows (since 2.7.2):
115115

116116
Kiba::Extend.config.default_job_method_name = :whatever
117117

118-
#### `Module` creator example (since 2.7.2)
118+
* If the method that runs the job is a module instance method with the default job method name, the `:creator` can be the `Module` containing that method
119119

120120
This is valid because the default `:job` method is present in the module:
121121

@@ -142,15 +142,15 @@ reghash = {
142142

143143
#### `Method` creator example
144144

145-
Default `:job` method not present (or is not the method you need to call for this job).
145+
If the method that runs the job is not the default job method name, you must set a `Method` as `:creator`:
146146

147147
~~~ ruby
148148
# in job definitions
149149
module Project
150150
module Table
151151
module_function
152152

153-
def prep
153+
def prepjob
154154
Kiba::Extend::Jobs::Job.new(
155155
...
156156
)
@@ -161,19 +161,22 @@ end
161161
# in file registry
162162
reghash = {
163163
path: '/project/working/objects_prep.csv',
164-
creator: Project::Table.method(:prep)
164+
creator: Project::Table.method(:prepjob)
165165
}
166166
~~~
167167

168168
#### `Hash` creator example (since 2.7.2)
169169

170+
You may wish to call a job with arguments if the same job logic can be reused many times with slightly different parameters. In this case, `:creator` may be a Hash with `callee` and `args` keys
171+
170172
Hash keys:
171173

172174
* `callee`: `Method` or `Module` (as described above)
173175
* `args`: `Hash` of keyword arguments to pass to the callee
174176

177+
In your project's `registry_data.rb`:
178+
175179
~~~ ruby
176-
# in your project's registry_data.rb
177180
module Project
178181
module RegistryData
179182
module_function
@@ -193,20 +196,23 @@ module Project
193196

194197
def register_lookups
195198
types = [
196-
'Accession Review Decision', 'Accession Type', 'Account Codes', 'ArchSite', 'Box', 'Budget Code',
197-
'Building', 'CityState', 'Cleaning', 'Condition Picks', 'Contact Type', 'Count Unit', 'Creator Type',
198-
'Cultural Affiliation', 'Department Code', 'Digitize Parameters', 'Digitizing Hardware',
199-
'Digitizing Software', 'Disposal Type', 'Exhibit Type', 'Format/Type', 'Genre', 'Image Resolution',
200-
'In Exhibit', 'Insured By', 'Loan Purpose', 'Material', 'Mount', 'NAGPRA Type', 'Owner Type',
201-
'Region', 'Room', 'Server Path', 'Technique', 'Treatment', 'Value'
199+
'Accession Review Decision', 'Accession Type', 'Account Codes', 'ArchSite'
202200
]
203201

204-
# This section dynamically registers a job for each of the above `types` values
202+
# This section dynamically registers a job for each of the above `types` values within the
203+
# `lkup` namespace
205204
Project.registry.namespace('lkup') do
206205
types.each do |type|
207206
register Project::RegistryData.normalized_lookup_type(type).to_sym, {
208-
path: File.join(Project.datadir, 'working', "#{Project::RegistryData.normalized_lookup_type(type)}.csv"),
209-
creator: {callee: Project::Main::Lookups::Extract, args: {type: type}},
207+
path: File.join(
208+
Project.datadir,
209+
'working',
210+
"#{Project::RegistryData.normalized_lookup_type(type)}.csv"
211+
),
212+
creator: {
213+
callee: Project::Main::Lookups::Extract,
214+
args: {type: type}
215+
},
210216
tags: %i[lkup],
211217
lookup_on: :lookupvalueid
212218
}
@@ -215,12 +221,16 @@ module Project
215221
end
216222

217223
def register files
218-
...
224+
# ...snip...
219225
end
220226
end
221227
end
228+
~~~
222229

223-
# in job definitions
230+
231+
In your job definition Module:
232+
233+
~~~ ruby
224234
module Project
225235
module Main
226236
module Lookups
@@ -231,15 +241,18 @@ module Project
231241
Kiba::Extend::Jobs::Job.new(
232242
files: {
233243
source: :lkup__prep,
234-
destination: "lkup__#{Project::RegistryData.normalized_lookup_type(type).to_sym}".to_sym
244+
destination: :"lkup__#{Project::RegistryData.normalized_lookup_type(type)}"
235245
},
236246
transformer: xforms(type)
237247
)
238248
end
239249

240250
def xforms(type)
241251
Kiba.job_segment do
242-
transform FilterRows::FieldEqualTo, action: :keep, field: :lookup_type, value: type
252+
transform FilterRows::FieldEqualTo,
253+
action: :keep,
254+
field: :lookup_type,
255+
value: type
243256
end
244257
end
245258
end
@@ -249,14 +262,13 @@ end
249262
~~~
250263

251264
### `:supplied`
252-
[true, false] whether the file/data is supplied from outside the ETL
265+
[true, false] whether the file/data is supplied from outside the kiba-extend project
253266

254267
- default: false
255268
- Manually set to true for:
256269
- original data files from client
257270
- mappings/reconciliations to be merged into the ETL/migration
258271
- any other files created external to the ETL, which only need to be read from and never generated by the ETL process
259-
- entries where `:src_class` is {Kiba::Extend::Sources::Marc}
260272

261273
Both of the following are valid:
262274

@@ -279,12 +291,12 @@ reghash = {
279291

280292
If the output of a given entry is expected to be used as a lookup on only one field, set a `:lookup_on` value in the registry.
281293

282-
If you need to lookup in the output data on different columns, either within one job or in different jobs, this can be achieved by providing more information in the job definition's `files[:lookup]` value. See {Kiba::Extend::Jobs} for details. (Or you can register the same file multiple times under different file keys with different `:lookup_on` values, but yuck to that)
294+
If you need to lookup in the output data on different columns, either within one job or in different jobs, this can be achieved by providing more information in the job definition's `files[:lookup]` value, starting with v5.1.0. See {Kiba::Extend::Jobs} for details. (Or you can register the same file multiple times under different file keys with different `:lookup_on` values, but yuck to that)
283295

284296
Currently only the following types of registry entries can be used as lookups:
285297

286-
* `:supplied` = `true` and `:src_class` returns row/record Hashes
287-
* `:dest_class` writes/returns row/record Hashes
298+
* Supplied registry entries where the `:src_class` returns each row/record as a Ruby `Hash`
299+
* Job registry entries where the `as_source_class` class attribute of the `:dest_class` returns each row/record as a Ruby `Hash`
288300

289301
Other types of registry entries should not define a `:lookup_on` value.
290302

@@ -297,9 +309,11 @@ Other types of registry entries should not define a `:lookup_on` value.
297309
[Array (of Symbols)] list of arbitrary tags useful for categorizing data/jobs in your ETL
298310

299311
* optional
300-
* If set, you can filter to run only jobs tagged with a given tag (or tags)1
312+
* If set, you can filter to run only jobs tagged with a given tag (or tags)
301313
* Tags I commonly use:
302314
* :report_problems - reports that indicate something unexpected or that I need to do more work
303315
* :report_fyi - informational reports
304316
* :postmigcleanup - for reports I will need to generate for client after production migration is complete
305317
* :cspace or :ingest- final files ready to import
318+
319+
You can do `thor reg:tags` to see a list of all tags already defined in your registry.

0 commit comments

Comments
 (0)