Sha256: b8c76ac2d5043e6652241f19b7b5a0a28034e2dd15ac227732976063d0d5a0ab

Contents?: true

Size: 1.87 KB

Versions: 12

Compression:

Stored size: 1.87 KB

Contents

# Use case to update a target oozes
# @note
#   - `target_ids` => Expects options[:source][:file] where at least the 1st column should be the target entry `ids`
class Eco::API::UseCases::OozeSamples::TargetOozesUpdateCase < Eco::API::UseCases::OozeSamples::RegisterUpdateCase
  name "target-oozes-update-case"
  type :other

  private

  def with_each_entry
    batched_target_ids do |ids|
      ids.each do |id|
        if pending = queue_shift(id)
          if dirty?(pending)
            msg  = "Same entry 'id' appears more than once. "
            msg << "Launching update on '#{object_reference(pending)}' to be able to queue it back"
            console.warn msg
            update_ooze(pending)
          end
        end
        if ooz = ooze(id)
          yield(ooz)
        end
      end
      update_oozes
    end
  end

  def batched_target_ids
    raise "Missing block. It yields in slices of #{self.class.batch_size} ids" unless block_given?
    target_ids_preview
    pool = []
    target_ids.each do |id|
      pool << id
      if pool.length >= self.class.batch_size
        yield(pool)
        pool = []
      end
    end
    yield(pool) unless pool.empty?
  end

  def target_ids_preview
    dups = target_ids.select {|id| target_ids.count(id) > 1}
    dups_str = dups.count > 0 ? "There are #{dups.count} duplicated ids" : "No duplicates detected"
    msg = "Total target entries: #{target_ids.count} (#{dups_str})"
    session.prompt_user("Do you want to proceed (y/N):", explanation: msg, default: "N", timeout: 10) do |res|
      unless res.upcase.start_with?("Y")
        puts "..."
        logger.info "Aborting script..."
        exit(0)
      end
    end
  end

  def target_ids
    @target_ids ||= input_csv.columns.first[1..-1]
  end

  def input_csv
    @input_csv ||= Eco::CSV.read(options.dig(:source, :file))
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
eco-helpers-2.6.1 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.6.0 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.5.10 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.5.9 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.5.8 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.5.7 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.5.6 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.5.5 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.5.4 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.5.3 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.5.2 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.5.1 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb