class RocketJob::Sliced::Writer::Output
Internal class for writing categorized results into output slices
Public Class Methods
collect(job, **args) { |writer| ... }
click to toggle source
Collect output results and write to output collections iff job is collecting output Notes:
Partial slices are saved when an exception is raised inside the block
# File lib/rocket_job/sliced/writer/output.rb, line 30 def self.collect(job, **args) writer = job.output_categories.present? ? new(job, **args) : Null.new(job, **args) yield(writer) ensure writer&.close end
Public Instance Methods
<<(result)
click to toggle source
Writes the supplied result, RocketJob::Batch::Result or RocketJob::Batch::Results
to the relevant collections
# File lib/rocket_job/sliced/writer/output.rb, line 39 def <<(result) if result.is_a?(RocketJob::Batch::Results) result.each { |single| extract_categorized_result(single) } else extract_categorized_result(result) end end
close()
click to toggle source
Write categorized results to their relevant collections
# File lib/rocket_job/sliced/writer/output.rb, line 48 def close categorized_records.each_pair do |category, results| collection = job.output(category) append ? collection.append(results, input_slice) : collection.insert(results, input_slice) end end
Private Instance Methods
extract_categorized_result(result)
click to toggle source
Stores the categorized result from one result
# File lib/rocket_job/sliced/writer/output.rb, line 58 def extract_categorized_result(result) named_category = :main value = result if result.is_a?(RocketJob::Batch::Result) named_category = result.category value = result.value end (categorized_records[named_category] ||= []) << value unless value.nil? && !job.output_category(named_category).nils end