trabajo-afectivo/lib/application_handle_info.rb

43 lines
1,019 B
Ruby
Raw Permalink Normal View History

2022-01-01 13:38:12 +00:00
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
module ApplicationHandleInfo
# stores current application handler.
# for example application_server, scheduler, websocket, postmaster...
thread_mattr_accessor :current
2017-11-23 08:09:44 +00:00
def self.postmaster?
return false if current.blank?
2017-11-23 08:09:44 +00:00
current.split('.')[1] == 'postmaster'
end
def self.use(name)
raise ArgumentError, 'requires a block' if !block_given?
orig = current
self.current = name
yield
ensure
self.current = orig
end
# stores action context
# for example merge, twitter, telegram....
# used to determine if custom attribute validation shall run
thread_mattr_accessor :context
def self.in_context(name)
raise ArgumentError, 'requires a block' if !block_given?
orig = context
self.context = name
yield
ensure
self.context = orig
end
def self.context_without_custom_attributes?
%w[merge twitter telegram facebook form mail sms].include? context.to_s
end
end