lib/rocket_job/batch/tabular/input.rb in rocketjob-5.0.0.rc1 vs lib/rocket_job/batch/tabular/input.rb in rocketjob-5.0.0

- old
+ new

@@ -11,22 +11,22 @@ 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 - # tabular_input_mode: [:line | :row | :record] + # tabular_input_mode: [:line | :array | :hash] # :line # Uploads the file a line (String) at a time for processing by workers. - # :row + # :array # Parses each line from the file as an Array and uploads each array for processing by workers. - # :record + # :hash # Parses each line from the file into a Hash and uploads each hash for processing by workers. - # See IOStreams#each_line, IOStreams#each_row, and IOStreams#each_record. + # See IOStreams#each. field :tabular_input_mode, type: Symbol, default: :line, class_attribute: true, user_editable: true, copy_on_restart: true validates_inclusion_of :tabular_input_format, in: IOStreams::Tabular.registered_formats - validates_inclusion_of :tabular_input_mode, in: %i[line row record] + validates_inclusion_of :tabular_input_mode, in: %i[line array hash row record] validate :tabular_input_header_present class_attribute :tabular_input_white_list class_attribute :tabular_input_required class_attribute :tabular_input_skip_unknown @@ -70,20 +70,20 @@ parse_header = -> (line) do tabular_input.parse_header(line) tabular_input_cleanse_header self.tabular_input_header = tabular_input.header.columns end - super(input_stream, on_first: parse_header, stream_mode: tabular_input_mode, **args, &block) - when :row + super(input_stream, on_first: parse_header, stream_mode: :line, **args, &block) + when :array, :row set_header = -> (row) do tabular_input.header.columns = row tabular_input_cleanse_header self.tabular_input_header = tabular_input.header.columns end - super(input_stream, on_first: set_header, stream_mode: tabular_input_mode, **args, &block) - when :record - super(input_stream, stream_mode: tabular_input_mode, **args, &block) + super(input_stream, on_first: set_header, stream_mode: :array, **args, &block) + when :hash, :record + super(input_stream, stream_mode: :hash, **args, &block) else raise(ArgumentError, "Invalid tabular_input_mode: #{stream_mode.inspect}") end end @@ -111,10 +111,10 @@ self.tabular_input_header = tabular_input.header.columns end def tabular_input_header_present - return if tabular_input_header.present? || !tabular_input.header? || (tabular_input_mode == :record) + return if tabular_input_header.present? || !tabular_input.header? || (tabular_input_mode == :hash || tabular_input_mode == :record) errors.add(:tabular_input_header, "is required when tabular_input_format is #{tabular_input_format.inspect}") end end end