Module: SidekiqUniqueJobs::Web::Helpers
- Defined in:
- lib/sidekiq_unique_jobs/web/helpers.rb
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__)
- SAFE_CPARAMS =
Returns safe params.
%w[cursor prev_cursor].freeze
Class Method Summary collapse
-
.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.
-
.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_template(name) ⇒ String
Opens a template file contained within this gem.
Class Method Details
.cparams(options) ⇒ String
Creates url safe parameters
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 48 def cparams() # stringify .transform_keys(&:to_s) params.merge().map do |key, value| next unless SAFE_CPARAMS.include?(key) "#{key}=#{CGI.escape(value.to_s)}" end.compact.join("&") end |
.digests ⇒ SidekiqUniqueJobs::Digests
The collection of digests
37 38 39 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 37 def digests @digests ||= SidekiqUniqueJobs::Digests.new end |
.display_lock_args(args, truncate_after_chars = 2000) ⇒ String
Used to avoid incompatibility with older sidekiq versions
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 68 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 |
.parse_time(time) ⇒ Time
Constructs a time from a number of different types
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 130 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
88 89 90 91 92 93 94 95 96 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 88 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
105 106 107 108 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 105 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
117 118 119 120 121 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 117 def safe_relative_time(time) time = parse_time(time) relative_time(time) end |
.unique_template(name) ⇒ String
Opens a template file contained within this gem
27 28 29 |
# File 'lib/sidekiq_unique_jobs/web/helpers.rb', line 27 def unique_template(name) File.open(File.join(VIEW_PATH, "#{name}.erb")).read end |