application_handle_info.rb 1019 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module ApplicationHandleInfo
  3. # stores current application handler.
  4. # for example application_server, scheduler, websocket, postmaster...
  5. thread_mattr_accessor :current
  6. def self.postmaster?
  7. return false if current.blank?
  8. current.split('.')[1] == 'postmaster'
  9. end
  10. def self.use(name)
  11. raise ArgumentError, 'requires a block' if !block_given?
  12. orig = current
  13. self.current = name
  14. yield
  15. ensure
  16. self.current = orig
  17. end
  18. # stores action context
  19. # for example merge, twitter, telegram....
  20. # used to determine if custom attribute validation shall run
  21. thread_mattr_accessor :context
  22. def self.in_context(name)
  23. raise ArgumentError, 'requires a block' if !block_given?
  24. orig = context
  25. self.context = name
  26. yield
  27. ensure
  28. self.context = orig
  29. end
  30. def self.context_without_custom_attributes?
  31. %w[merge twitter telegram facebook form mail sms].include? context.to_s
  32. end
  33. end