Module: ClockworkWeb::HomeHelper
- Defined in:
- app/helpers/clockwork_web/home_helper.rb
Instance Method Summary collapse
- #friendly_extract_source_from_callable(callable, with_affixes: true) ⇒ Object
- #friendly_period(period) ⇒ Object
- #friendly_should_have_run(event, last_run) ⇒ Object
- #friendly_time_part(time_part) ⇒ Object
- #last_run(time) ⇒ Object
- #overdue?(event, last_run) ⇒ Boolean
- #should_have_run_at(event, last_run) ⇒ Object
Instance Method Details
#friendly_extract_source_from_callable(callable, with_affixes: true) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/clockwork_web/home_helper.rb', line 44 def friendly_extract_source_from_callable(callable, with_affixes: true) iseq = RubyVM::InstructionSequence.of(callable) source = if iseq.script_lines iseq.script_lines.join("\n") elsif File.readable?(iseq.absolute_path) File.read(iseq.absolute_path) end return '-' unless source location = iseq.to_a[4][:code_location] return callable unless location lines = source.lines[(location[0] - 1)..(location[2] - 1)] lines[-1] = lines[-1].byteslice(...location[3]) lines[0] = lines[0].byteslice(location[1]...) source = lines.join.strip source.tap do |source| source.delete_prefix!('{') source.delete_suffix!('}') source.delete_prefix!('do') source.delete_suffix!('end') end end |
#friendly_period(period) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/clockwork_web/home_helper.rb', line 3 def friendly_period(period) if period % 1.day == 0 pluralize(period / 1.day, "day") elsif period % 1.hour == 0 pluralize(period / 1.hour, "hour") elsif period % 1.minute == 0 "#{period / 1.minute} min" else "#{period} sec" end end |
#friendly_should_have_run(event, last_run) ⇒ Object
37 38 39 40 41 42 |
# File 'app/helpers/clockwork_web/home_helper.rb', line 37 def friendly_should_have_run(event, last_run) at = should_have_run_at(event, last_run) if at "#{time_ago_in_words(at, include_seconds: true)} ago" end end |
#friendly_time_part(time_part) ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/helpers/clockwork_web/home_helper.rb', line 21 def friendly_time_part(time_part) if time_part time_part.to_s.rjust(2, "0") else "**" end end |
#last_run(time) ⇒ Object
15 16 17 18 19 |
# File 'app/helpers/clockwork_web/home_helper.rb', line 15 def last_run(time) if time "#{time_ago_in_words(time, include_seconds: true)} ago" end end |
#overdue?(event, last_run) ⇒ Boolean
29 30 31 |
# File 'app/helpers/clockwork_web/home_helper.rb', line 29 def overdue?(event, last_run) ClockworkWeb.overdue?(event, last_run) end |
#should_have_run_at(event, last_run) ⇒ Object
33 34 35 |
# File 'app/helpers/clockwork_web/home_helper.rb', line 33 def should_have_run_at(event, last_run) ClockworkWeb.should_have_run_at(event, last_run) end |