Module: Bp3::Noticed::CommonIncludes
- Extended by:
- ActiveSupport::Concern
- Included in:
- PrependPerform
- Defined in:
- lib/bp3/noticed/common_includes.rb
Instance Method Summary collapse
- #check(hash_or_array, key) ⇒ Object private
- #ensure_site ⇒ Object private
- #global_request_state_class ⇒ Object
- #include_log_error(key:, message:, details: {}) ⇒ Object private
- #job_key ⇒ Object private
- #run ⇒ Object
- #set_global_request_state ⇒ Object private
- #site_class ⇒ Object private
- #state ⇒ Object private
Instance Method Details
#check(hash_or_array, key) ⇒ Object (private)
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bp3/noticed/common_includes.rb', line 62 def check(hash_or_array, key) return nil if hash_or_array.blank? if hash_or_array.is_a?(Array) hash_or_array.each do |obj| value = check(obj, key) return value if value end nil elsif hash_or_array.is_a?(Hash) hash_or_array[key.to_s] || hash_or_array[key.to_sym] end end |
#ensure_site ⇒ Object (private)
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bp3/noticed/common_includes.rb', line 37 def ensure_site id = run_attrs(:sites_site_id) || run_attrs(:site_id) if id.present? site = site_class.find_by(id:) return site if site.present? = "Unable to find site #{id}" include_log_error(key: 'prepend_state.ensure_site', message:) end site_class.root_site || site_class.first end |
#global_request_state_class ⇒ Object
18 19 20 |
# File 'lib/bp3/noticed/common_includes.rb', line 18 def global_request_state_class Bp3::Core::Rqid.global_request_state_class end |
#include_log_error(key:, message:, details: {}) ⇒ Object (private)
50 51 52 53 54 55 56 |
# File 'lib/bp3/noticed/common_includes.rb', line 50 def include_log_error(key:, message:, details: {}) return log_error(key:, message:, details:) if respond_to?(:log_error, true) = "Warning: #{self.class.name}#log_info: unable to log error #{key}/#{}/#{details}" Rails.logger.warn { } nil end |
#job_key ⇒ Object (private)
76 77 78 |
# File 'lib/bp3/noticed/common_includes.rb', line 76 def job_key self.class.name.underscore end |
#run ⇒ Object
22 23 24 |
# File 'lib/bp3/noticed/common_includes.rb', line 22 def run(...) perform(...) end |
#set_global_request_state ⇒ Object (private)
28 29 30 31 |
# File 'lib/bp3/noticed/common_includes.rb', line 28 def set_global_request_state global_request_state_class.from_hash(state) global_request_state_class.current_site ||= ensure_site end |
#site_class ⇒ Object (private)
58 59 60 |
# File 'lib/bp3/noticed/common_includes.rb', line 58 def site_class Bp3::ActionDispatch.site_class end |
#state ⇒ Object (private)
33 34 35 |
# File 'lib/bp3/noticed/common_includes.rb', line 33 def state run_attrs :state end |