Module: Remi::Job
- Defined in:
- lib/remi/job.rb
Defined Under Namespace
Modules: JobClassMethods
Instance Attribute Summary collapse
-
#runtime_params ⇒ Object
Returns the value of attribute runtime_params.
Class Method Summary collapse
Instance Method Summary collapse
- #create_work_dir ⇒ Object
- #delete_work_dir ⇒ Object
- #finalize ⇒ Object
- #initialize(runtime_params: {}, delete_work_dir: true, logger: Settings.logger) ⇒ Object
- #load_all_targets ⇒ Object
- #lookups ⇒ Object
- #params ⇒ Object
-
#run ⇒ Object
Public: Runs all transforms defined in the job.
- #run_all_transforms ⇒ Object
-
#run_transforms_using(sources: nil, targets: nil) ⇒ Object
Public: Runs any transforms that use the sources and targets selected.
- #sources ⇒ Object
- #targets ⇒ Object
- #transforms ⇒ Object
- #work_dir ⇒ Object
Instance Attribute Details
#runtime_params ⇒ Object
Returns the value of attribute runtime_params.
140 141 142 |
# File 'lib/remi/job.rb', line 140 def runtime_params @runtime_params end |
Class Method Details
.included(receiver) ⇒ Object
106 107 108 |
# File 'lib/remi/job.rb', line 106 def self.included(receiver) receiver.extend(JobClassMethods) end |
Instance Method Details
#create_work_dir ⇒ Object
160 161 162 163 |
# File 'lib/remi/job.rb', line 160 def create_work_dir @logger.info "Creating working directory #{work_dir}" FileUtils.mkdir_p work_dir end |
#delete_work_dir ⇒ Object
150 151 152 153 154 155 156 157 158 |
# File 'lib/remi/job.rb', line 150 def delete_work_dir if @delete_work_dir && (work_dir.match /^#{Dir.tmpdir}/) @logger.info "Deleting temporary directory #{work_dir}" FileUtils.rm_r work_dir else @logger.debug "Not going to delete working directory #{work_dir}" nil end end |
#finalize ⇒ Object
146 147 148 |
# File 'lib/remi/job.rb', line 146 def finalize delete_work_dir end |
#initialize(runtime_params: {}, delete_work_dir: true, logger: Settings.logger) ⇒ Object
133 134 135 136 137 138 |
# File 'lib/remi/job.rb', line 133 def initialize(runtime_params: {}, delete_work_dir: true, logger: Settings.logger) @runtime_params = runtime_params @delete_work_dir = delete_work_dir @logger = logger create_work_dir end |
#load_all_targets ⇒ Object
186 187 188 189 190 191 |
# File 'lib/remi/job.rb', line 186 def load_all_targets targets.each do |target| @logger.info "Loading target #{target}" self.send(target).tap { |t| t.respond_to?(:load) ? t.load : nil } end end |
#lookups ⇒ Object
115 116 117 |
# File 'lib/remi/job.rb', line 115 def lookups self.class.lookups end |
#params ⇒ Object
111 112 113 |
# File 'lib/remi/job.rb', line 111 def params self.class.params end |
#run ⇒ Object
Public: Runs all transforms defined in the job.
Returns the job instance.
196 197 198 199 200 201 |
# File 'lib/remi/job.rb', line 196 def run # Do all of the stuff here run_all_transforms load_all_targets self end |
#run_all_transforms ⇒ Object
182 183 184 |
# File 'lib/remi/job.rb', line 182 def run_all_transforms transforms.map { |t, st| self.send(t) } end |
#run_transforms_using(sources: nil, targets: nil) ⇒ Object
Public: Runs any transforms that use the sources and targets selected. If source and target is not specified, then all transforms will be run. If only the source is specified, then all transforms that use any of the sources will be run. Same for specified transforms.
sources - Array of source names targets - Array of target names
Returns an array containing the result of each transform.
174 175 176 177 178 179 180 |
# File 'lib/remi/job.rb', line 174 def run_transforms_using(sources: nil, targets: nil) transforms.map do |t, st| selected_sources = (st[:sources] & Array(sources || st[:sources])).size > 0 selected_targets = (st[:targets] & Array(targets || st[:targets])).size > 0 self.send(t) if selected_sources && selected_targets end end |
#sources ⇒ Object
119 120 121 |
# File 'lib/remi/job.rb', line 119 def sources self.class.sources end |
#targets ⇒ Object
123 124 125 |
# File 'lib/remi/job.rb', line 123 def targets self.class.targets end |
#transforms ⇒ Object
127 128 129 |
# File 'lib/remi/job.rb', line 127 def transforms self.class.transforms end |
#work_dir ⇒ Object
142 143 144 |
# File 'lib/remi/job.rb', line 142 def work_dir self.class.work_dir end |