Module: GoodJob::ApplicationHelper

Includes:
IconsHelper
Defined in:
app/helpers/good_job/application_helper.rb

Constant Summary

Constants included from IconsHelper

IconsHelper::STATUS_COLOR, IconsHelper::STATUS_ICONS

Instance Method Summary collapse

Methods included from IconsHelper

#icons_path, #render_icon, #status_badge, #status_icon

Instance Method Details

#format_duration(sec) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/good_job/application_helper.rb', line 20

def format_duration(sec)
  return unless sec
  return "" if sec.is_a?(String) # pg interval support added in Rails 6.1

  if sec < 1
    t 'good_job.duration.milliseconds', ms: (sec * 1000).floor
  elsif sec < 10
    t 'good_job.duration.less_than_10_seconds', sec: number_with_delimiter(sec.floor(1))
  elsif sec < 60
    t 'good_job.duration.seconds', sec: sec.floor
  elsif sec < 3600
    t 'good_job.duration.minutes', min: (sec / 60).floor, sec: (sec % 60).floor
  else
    t 'good_job.duration.hours', hour: (sec / 3600).floor, min: ((sec % 3600) / 60).floor
  end
end

#job_action_statesObject



10
11
12
13
14
15
16
17
18
# File 'app/helpers/good_job/application_helper.rb', line 10

def job_action_states
  {
    reschedule: %w[scheduled retried queued],
    retry: %w[discarded],
    discard: %w[scheduled retried queued],
    force_discard: %w[running],
    destroy: %w[discarded succeeded],
  }
end

#number_to_human(count) ⇒ Object



43
44
45
# File 'app/helpers/good_job/application_helper.rb', line 43

def number_to_human(count)
  super(count, **translate_hash("good_job.number.human.decimal_units"))
end

#number_with_delimiter(count) ⇒ Object



47
48
49
# File 'app/helpers/good_job/application_helper.rb', line 47

def number_with_delimiter(count)
  super(count, **translate_hash('good_job.number.format'))
end

#relative_time(timestamp, **options) ⇒ Object



37
38
39
40
41
# File 'app/helpers/good_job/application_helper.rb', line 37

def relative_time(timestamp, **options)
  options = options.reverse_merge({ scope: "good_job.datetime.distance_in_words" })
  text = t("good_job.helpers.relative_time.#{timestamp.future? ? 'future' : 'past'}", time: time_ago_in_words(timestamp, **options))
  tag.time(text, datetime: timestamp, title: timestamp)
end

#translate_hash(key, **options) ⇒ Object



51
52
53
# File 'app/helpers/good_job/application_helper.rb', line 51

def translate_hash(key, **options)
  translation_exists?(key, **options) ? translate(key, **options) : {}
end

#translation_exists?(key, **options) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/helpers/good_job/application_helper.rb', line 55

def translation_exists?(key, **options)
  I18n.exists?(scope_key_by_partial(key), **options)
end