Module: Bp3::Noticed::CommonIncludes

Extended by:
ActiveSupport::Concern
Included in:
PrependPerform
Defined in:
lib/bp3/noticed/common_includes.rb

Instance Method Summary collapse

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_siteObject (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?

    message = "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_classObject



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)

  message = "Warning: #{self.class.name}#log_info: unable to log error #{key}/#{message}/#{details}"
  Rails.logger.warn { message }
  nil
end

#job_keyObject (private)



76
77
78
# File 'lib/bp3/noticed/common_includes.rb', line 76

def job_key
  self.class.name.underscore
end

#runObject



22
23
24
# File 'lib/bp3/noticed/common_includes.rb', line 22

def run(...)
  perform(...)
end

#set_global_request_stateObject (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_classObject (private)



58
59
60
# File 'lib/bp3/noticed/common_includes.rb', line 58

def site_class
  Bp3::ActionDispatch.site_class
end

#stateObject (private)



33
34
35
# File 'lib/bp3/noticed/common_includes.rb', line 33

def state
  run_attrs :state
end