Module: Kiba::Extend::Jobs::Runnable
- Includes:
- Reportable
- Included in:
- BaseJob
- Defined in:
- lib/kiba/extend/jobs/runnable.rb
Overview
The methods that need to be mixed in to a Job to make it run
These methods are intended to be agnostic of the job segment/step logic,
which is why they are separated out into a module
Instance Method Summary
collapse
Methods included from Reportable
#desc_and_tags, #get_duration, #minimal_end, #minimal_start, #normal_end, #normal_start, #put_file_details, #report_run_end, #report_run_start, #row_report, #start_and_def, #start_label, #tags, #verbose_end, #verbose_start
Instance Method Details
#add_config ⇒ Object
This stuff does not get handled by parsing source code
42
43
44
45
46
|
# File 'lib/kiba/extend/jobs/runnable.rb', line 42
def add_config
return if config.empty?
control.config.merge(config)
end
|
#add_decoration ⇒ Object
13
14
15
16
|
# File 'lib/kiba/extend/jobs/runnable.rb', line 13
def add_decoration
show_me_decoration
tell_me_decoration
end
|
#add_destinations ⇒ Object
48
49
50
|
# File 'lib/kiba/extend/jobs/runnable.rb', line 48
def add_destinations
context.instance_eval(destinations)
end
|
#add_lookup(config) ⇒ Object
Add lookup tables to the context as methods memoized to instance
variables
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/kiba/extend/jobs/runnable.rb', line 20
def add_lookup(config)
cust = :@instance_variable_name
name = if config.instance_variable_defined?(cust)
config.instance_variable_get(cust)
else
config.key
end
ivname = :"@#{name}"
context.define_singleton_method(name.to_sym) do
if instance_variable_defined?(ivname)
instance_variable_get(ivname)
else
instance_variable_set(
ivname,
Lookup.csv_to_hash(**config.args.compact)
)
end
end
end
|
#add_sources ⇒ Object
52
53
54
|
# File 'lib/kiba/extend/jobs/runnable.rb', line 52
def add_sources
context.instance_eval(sources)
end
|
#assemble_control ⇒ Object
56
57
58
59
60
61
62
63
64
|
# File 'lib/kiba/extend/jobs/runnable.rb', line 56
def assemble_control
lookups_to_memoized_methods if @files[:lookup]
parse_job_segments
add_config
add_sources
add_destinations
add_decoration
control
end
|
#lookups_to_memoized_methods ⇒ Object
66
67
68
69
70
|
# File 'lib/kiba/extend/jobs/runnable.rb', line 66
def lookups_to_memoized_methods
@files[:lookup].each do |config|
add_lookup(config)
end
end
|
#parse_job_segments ⇒ Object
The parts that get generated by parsing of Kiba code blocks
73
74
75
|
# File 'lib/kiba/extend/jobs/runnable.rb', line 73
def parse_job_segments
parse_job(control, context, [pre_process, transform, post_process])
end
|
#show_me_decoration ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/kiba/extend/jobs/runnable.rb', line 77
def show_me_decoration
return unless Kiba::Extend.job_show_me
extend ShowMeJob
decorate
end
|
#sources ⇒ Object
85
86
87
88
89
|
# File 'lib/kiba/extend/jobs/runnable.rb', line 85
def sources
@files[:source].map { |config| file_config(config) }
.map { |src| "source #{src[:klass]}, **#{src[:args]}" }
.join("\n")
end
|
#tell_me_decoration ⇒ Object
91
92
93
94
95
96
97
|
# File 'lib/kiba/extend/jobs/runnable.rb', line 91
def tell_me_decoration
return unless Kiba::Extend.job_tell_me
extend TellMeJob
decorate
end
|
99
100
101
|
# File 'lib/kiba/extend/jobs/runnable.rb', line 99
def transform
[initial_transforms, @transformer, final_transforms].flatten
end
|