action.rb 1.7 KB

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