Module: SolidQueueMonitor::ApplicationHelper

Defined in:
app/helpers/solid_queue_monitor/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#asset_url_for(file_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/solid_queue_monitor/application_helper.rb', line 5

def asset_url_for(file_name)
  base = File.basename(file_name, '.*')
  ext = File.extname(file_name)
  hash = SolidQueueMonitor::AssetCache.fingerprint_for(file_name)
  fingerprinted_file = "#{base}-#{hash}#{ext}"

  if respond_to?(:solid_queue_monitor)
    solid_queue_monitor.asset_path(file: fingerprinted_file)
  else
    SolidQueueMonitor::Engine.routes.url_helpers.asset_path(file: fingerprinted_file)
  end
end

#csrf_meta_tags_if_enabledObject

CSRF meta tags for JS/fetch-driven POSTs (defense in depth). Only emitted when CSRF protection is enabled, for the same reason.



39
40
41
42
43
# File 'app/helpers/solid_queue_monitor/application_helper.rb', line 39

def csrf_meta_tags_if_enabled
  return ''.html_safe unless SolidQueueMonitor.csrf_protection_enabled

  csrf_meta_tags
end

#csrf_token_field_if_enabledObject

Hidden authenticity_token field for raw HTML POST forms. Renders nothing unless CSRF protection is enabled, so hosts without a session store are unaffected (form_authenticity_token needs a session).



31
32
33
34
35
# File 'app/helpers/solid_queue_monitor/application_helper.rb', line 31

def csrf_token_field_if_enabled
  return ''.html_safe unless SolidQueueMonitor.csrf_protection_enabled

  hidden_field_tag(:authenticity_token, form_authenticity_token)
end

#format_datetime(datetime) ⇒ Object



18
19
20
21
22
# File 'app/helpers/solid_queue_monitor/application_helper.rb', line 18

def format_datetime(datetime)
  return '-' unless datetime

  datetime.strftime('%Y-%m-%d %H:%M:%S')
end

#message_class(type) ⇒ Object



24
25
26
# File 'app/helpers/solid_queue_monitor/application_helper.rb', line 24

def message_class(type)
  type.to_s == 'success' ? 'message-success' : 'message-error'
end


45
46
47
48
49
50
51
# File 'app/helpers/solid_queue_monitor/application_helper.rb', line 45

def queue_link(queue_name, css_class: nil)
  return '-' if queue_name.blank?

  link_to(queue_name,
          queue_details_url_for(queue_name),
          class: class_names('queue-link', css_class))
end