Module: SidekiqUniqueJobs::Web::Helpers
Overview
Provides view helpers for the Sidekiq::Web extension
Constant Summary collapse
- VIEW_PATH =
Returns the path to gem specific views.
File.("../web/views", __dir__).freeze
- SAFE_CPARAMS =
Returns safe params.
%w[ filter count cursor prev_cursor poll direction ].freeze
Instance Method Summary collapse
-
#changelog ⇒ SidekiqUniqueJobs::Digests
The collection of changelog entries.
-
#cparams(options) ⇒ String
Creates url safe parameters.
-
#digests ⇒ SidekiqUniqueJobs::Digests
The collection of digests.
-
#display_lock_args(args, truncate_after_chars = 2000) ⇒ String
Used to avoid incompatibility with older sidekiq versions.
-
#expiring_digests ⇒ SidekiqUniqueJobs::ExpiringDigests
The collection of digests.
-
#parse_time(time) ⇒ Time
Constructs a time from a number of different types.
-
#redirect_to(subpath) ⇒ Object
Redirect to with falback.
-
#relative_time(time) ⇒ String
Gets a relative time as html.
-
#safe_relative_time(time) ⇒ String
Gets a relative time as html without crashing.
-
#unique_filename(name) ⇒ String
Construct template file name.
-
#unique_template(name) ⇒ String
Opens a template file contained within this gem.
Instance Method Details
#changelog ⇒ SidekiqUniqueJobs::Digests
The collection of changelog entries
70 71 72 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 70 def changelog @changelog ||= SidekiqUniqueJobs::Changelog.new end |
#cparams(options) ⇒ String
Creates url safe parameters
81 82 83 84 85 86 87 88 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 81 def cparams() = .transform_keys(&:to_s) params.merge().filter_map do |key, value| next unless SAFE_CPARAMS.include?(key) "#{key}=#{CGI.escape(value.to_s)}" end.join("&") end |
#digests ⇒ SidekiqUniqueJobs::Digests
The collection of digests
50 51 52 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 50 def digests @digests ||= SidekiqUniqueJobs::Digests.new end |
#display_lock_args(args, truncate_after_chars = 2000) ⇒ String
Used to avoid incompatibility with older sidekiq versions
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 99 def display_lock_args(args, truncate_after_chars = 2000) return "Invalid job payload, args is nil" if args.nil? return "Invalid job payload, args must be an Array, not #{args.class.name}" unless args.is_a?(Array) begin args.map do |arg| h(truncate(to_display(arg), truncate_after_chars)) end.join(", ") rescue StandardError "Illegal job arguments: #{h args.inspect}" end end |
#expiring_digests ⇒ SidekiqUniqueJobs::ExpiringDigests
The collection of digests
60 61 62 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 60 def expiring_digests @expiring_digests ||= SidekiqUniqueJobs::ExpiringDigests.new end |
#parse_time(time) ⇒ Time
Constructs a time from a number of different types
163 164 165 166 167 168 169 170 171 172 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 163 def parse_time(time) case time when Time time when Integer, Float Time.at(time) else Time.parse(time.to_s) end end |
#redirect_to(subpath) ⇒ Object
Redirect to with falback
119 120 121 122 123 124 125 126 127 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 119 def redirect_to(subpath) if respond_to?(:to) # Sinatra-based web UI redirect to(subpath) else # Non-Sinatra based web UI (Sidekiq 4.2+) redirect "#{root_path}#{subpath}" end end |
#relative_time(time) ⇒ String
Gets a relative time as html
136 137 138 139 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 136 def relative_time(time) stamp = time.getutc.iso8601 %(<time class="ltr" dir="ltr" title="#{stamp}" datetime="#{stamp}">#{time}</time>) end |
#safe_relative_time(time) ⇒ String
Gets a relative time as html without crashing
148 149 150 151 152 153 154 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 148 def safe_relative_time(time) return unless time time = parse_time(time) relative_time(time) end |
#unique_filename(name) ⇒ String
Construct template file name
40 41 42 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 40 def unique_filename(name) File.join(VIEW_PATH, "#{name}.erb") end |
#unique_template(name) ⇒ String
Opens a template file contained within this gem
29 30 31 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 29 def unique_template(name) File.read(unique_filename(name)) end |