lib/rocket_job/batch/tabular/input.rb in rocketjob-5.3.2 vs lib/rocket_job/batch/tabular/input.rb in rocketjob-5.3.3

- old
+ new

@@ -10,10 +10,11 @@ extend ActiveSupport::Concern included do field :tabular_input_header, type: Array, class_attribute: true, user_editable: true field :tabular_input_format, type: Symbol, default: :csv, class_attribute: true, user_editable: true + field :tabular_input_options, type: Hash, class_attribute: true # tabular_input_mode: [:line | :array | :hash] # :line # Uploads the file a line (String) at a time for processing by workers. # :array @@ -51,11 +52,13 @@ # - When supplying a block the header must be set manually def upload(stream = nil, **args, &block) input_stream = stream.nil? ? nil : IOStreams.new(stream) if stream && (tabular_input_type == :text) - input_stream.option_or_stream(:encode, encoding: "UTF-8", cleaner: :printable, replace: "") + # Cannot change the length of fixed width lines + replace = tabular_input_format == :fixed ? " " : "" + input_stream.option_or_stream(:encode, encoding: "UTF-8", cleaner: :printable, replace: replace) end # If an input header is not required, then we don't extract it' return super(input_stream, stream_mode: tabular_input_mode, **args, &block) unless tabular_input.header? @@ -94,17 +97,18 @@ @tabular_input ||= IOStreams::Tabular.new( columns: tabular_input_header, allowed_columns: tabular_input_white_list, required_columns: tabular_input_required, skip_unknown: tabular_input_skip_unknown, - format: tabular_input_format + format: tabular_input_format, + format_options: tabular_input_options&.deep_symbolize_keys ) end def tabular_input_render - unless tabular_input_header.blank? && tabular_input.header? - @rocket_job_input = tabular_input.record_parse(@rocket_job_input) - end + return if tabular_input_header.blank? && tabular_input.header? + + @rocket_job_input = tabular_input.record_parse(@rocket_job_input) end # Cleanse custom input header if supplied. def tabular_input_cleanse_header ignored_columns = tabular_input.header.cleanse!