From 8ff221d2a2c6075b43eedfa7e77b8addee1fe086 Mon Sep 17 00:00:00 2001 From: chaadow Date: Sat, 14 Sep 2024 14:06:03 +0200 Subject: [PATCH] Display if block instead of placeholder --- app/helpers/clockwork_web/home_helper.rb | 16 ++++++++++++++++ app/views/clockwork_web/home/index.html.erb | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/helpers/clockwork_web/home_helper.rb b/app/helpers/clockwork_web/home_helper.rb index 3b82c7f..464955e 100644 --- a/app/helpers/clockwork_web/home_helper.rb +++ b/app/helpers/clockwork_web/home_helper.rb @@ -25,5 +25,21 @@ def friendly_time_part(time_part) "**" end end + + def friendly_extract_source_from_callable(callable, with_affixes: true) + source = RubyVM::AbstractSyntaxTree.of(callable, keep_script_lines: true).source + return '-' unless source + + source.strip! + return source if with_affixes + + source.tap do |source| + source.delete_prefix!('{') + source.delete_suffix!('}') + + source.delete_prefix!('do') + source.delete_suffix!('end') + end + end end end diff --git a/app/views/clockwork_web/home/index.html.erb b/app/views/clockwork_web/home/index.html.erb index d9cc85b..8243304 100644 --- a/app/views/clockwork_web/home/index.html.erb +++ b/app/views/clockwork_web/home/index.html.erb @@ -77,7 +77,7 @@ - + @@ -94,8 +94,8 @@ <% if at %> at <%= friendly_time_part(at.instance_variable_get(:@hour)) %>:<%= friendly_time_part(at.instance_variable_get(:@min)) %> <% end %> - <% if event.instance_variable_get(:@if) %> - if __ + <% if if_lambda = event.instance_variable_get(:@if) %> + if: -> <%= friendly_extract_source_from_callable(if_lambda)%> <% end %>
JobJob Period Last Run Action <%= last_run(@last_runs[event.job]) %>