lib/rocket_job/batch/tabular/output.rb in rocketjob-5.3.2 vs lib/rocket_job/batch/tabular/output.rb in rocketjob-5.3.3
- old
+ new
@@ -10,10 +10,11 @@
extend ActiveSupport::Concern
included do
field :tabular_output_header, type: Array, class_attribute: true, user_editable: true, copy_on_restart: true
field :tabular_output_format, type: Symbol, default: :csv, class_attribute: true, user_editable: true, copy_on_restart: true
+ field :tabular_output_options, type: Hash, class_attribute: true
validates_inclusion_of :tabular_output_format, in: IOStreams::Tabular.registered_formats
after_perform :tabular_output_render
end
@@ -29,22 +30,27 @@
@tabular_output = nil
end
# Overrides: `RocketJob::Batch::IO#download` to add the `tabular_output_header`.
def download(file_name_or_io = nil, category: :main, **args, &block)
- # No header required
- return super(file_name_or_io, category: category, **args, &block) unless tabular_output.requires_header?(category)
+ unless tabular_output.requires_header?(category)
+ return super(file_name_or_io, category: category, **args, &block)
+ end
header = tabular_output.render_header(category)
super(file_name_or_io, header_line: header, category: category, **args, &block)
end
private
# Delimited instance used for this slice, by a single worker (thread)
def tabular_output
@tabular_output ||= Tabular.new(
- main: IOStreams::Tabular.new(columns: tabular_output_header, format: tabular_output_format)
+ main: IOStreams::Tabular.new(
+ columns: tabular_output_header,
+ format: tabular_output_format,
+ format_options: tabular_output_options&.deep_symbolize_keys
+ )
)
end
# Render the output from the perform.
def tabular_output_render