Sha256: 9423f9ba55eeff6e837d02750d62585d0b88b6af664361409c0d4be3c7292122

Contents?: true

Size: 1.87 KB

Versions: 54

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

54 entries across 54 versions & 1 rubygems

Version Path
eco-helpers-2.4.9 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.4.8 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.4.7 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.4.6 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.4.5 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.4.4 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.4.3 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.4.2 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.3.3 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.3.2 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.2.5 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.2.4 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.2.3 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.2.2 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.2.1 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.1.12 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.1.11 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.1.10 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.1.9 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb
eco-helpers-2.1.8 lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb