base.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # This unit checks if an Sequencer state attribute (e.g. `mapped`) is blank.
  3. # Don't confuse it with e.g. 'Import::Common::Model::Skip::MissingMandatory::Base' which checks if an attribute key (e.g. mapped[:some_key]) is blank/missing.
  4. class Sequencer::Unit::Import::Common::Model::Skip::Blank::Base < Sequencer::Unit::Base
  5. include ::Sequencer::Unit::Common::Mixin::DynamicAttribute
  6. prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action
  7. include ::Sequencer::Unit::Import::Common::Model::Mixin::Log::ContextIdentificationString
  8. skip_any_action
  9. provides :action
  10. optional :model_class
  11. def process
  12. return if !skip?
  13. logger.info { skip_log_message }
  14. state.provide(:action, :skipped)
  15. end
  16. private
  17. def ignore
  18. [:id]
  19. end
  20. def skip?
  21. return true if attribute_value.blank?
  22. relevant_blank?
  23. end
  24. def skip_log_message
  25. "Skipping. Blank attribute '#{attribute}' found (#{attribute_value.inspect})#{context_identification_string}"
  26. end
  27. def relevant_blank?
  28. attribute_value.except(*ignore).values.none?(&:present?)
  29. end
  30. end