Module: JobBoard::ApplicationHelper

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

Instance Method Summary collapse

Instance Method Details

#duration(seconds) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/job_board/application_helper.rb', line 15

def duration(seconds)
  seconds = seconds.to_i
  return "0s" if seconds <= 0

  parts = { "d" => 86400, "h" => 3600, "m" => 60, "s" => 1 }.filter_map do |unit, size|
    value, seconds = seconds.divmod(size)
    "#{value}#{unit}" if value.positive?
  end
  parts.first(2).join(" ")
end

#format_json(value) ⇒ Object



33
34
35
36
37
38
# File 'app/helpers/job_board/application_helper.rb', line 33

def format_json(value)
  value = JSON.parse(value) if value.is_a?(String)
  JSON.pretty_generate(value)
rescue JSON::ParserError, JSON::GeneratorError
  value.to_s
end

#latency_threshold_for(queue_name) ⇒ Object

Latency (seconds) above which a queue counts as breaching. Resolution order: explicit per-queue config, a threshold parsed from a within_* style name, then the global default.



29
30
31
# File 'app/helpers/job_board/application_helper.rb', line 29

def latency_threshold_for(queue_name)
  LatencySla.threshold_for(queue_name)
end

#status_badge(status) ⇒ Object



3
4
5
# File 'app/helpers/job_board/application_helper.rb', line 3

def status_badge(status)
  tag.span(status.to_s.humanize, class: "badge badge--#{status}")
end

#time_ago(time) ⇒ Object



7
8
9
10
11
12
13
# File 'app/helpers/job_board/application_helper.rb', line 7

def time_ago(time)
  return tag.span("", class: "muted") if time.blank?

  time = Time.zone.parse(time) if time.is_a?(String)
  tag.time("#{duration((Time.current - time).abs)} #{time.future? ? "from now" : "ago"}",
    title: time.iso8601, datetime: time.iso8601)
end