action.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action
  3. module ClassMethods
  4. def skip_action(*actions)
  5. declaration_accessor(
  6. key: __method__,
  7. attributes: actions
  8. )
  9. end
  10. alias skip_actions skip_action
  11. def skip_any_action
  12. skip_actions(:any)
  13. end
  14. def skip_action?(action)
  15. logger.debug { "Checking if skip is necessary for action #{action.inspect}." }
  16. return false if action.blank?
  17. logger.debug { "Checking if skip is necessary for skip_actions #{skip_actions.inspect}." }
  18. return false if skip_actions.blank?
  19. return true if skip_actions.include?(action)
  20. return true if skip_actions.include?(:any)
  21. false
  22. end
  23. end
  24. def self.prepended(base)
  25. base.optional :action
  26. base.extend(ClassMethods)
  27. end
  28. def process
  29. if self.class.skip_action?(action)
  30. logger.debug { "Skipping due to provided action #{action.inspect}." }
  31. else
  32. logger.debug { "Nope. Won't skip action #{action.inspect}." }
  33. super
  34. end
  35. end
  36. end