Class: JobPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq-web-workers/job_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_name) ⇒ JobPresenter

Returns a new instance of JobPresenter.



4
5
6
# File 'lib/sidekiq-web-workers/job_presenter.rb', line 4

def initialize(job_name)
  @worker_name = job_name
end

Instance Attribute Details

#worker_nameObject (readonly)

Returns the value of attribute worker_name.



2
3
4
# File 'lib/sidekiq-web-workers/job_presenter.rb', line 2

def worker_name
  @worker_name
end

Instance Method Details

#descriptionObject



8
9
10
# File 'lib/sidekiq-web-workers/job_presenter.rb', line 8

def description
  job_constantized.respond_to?(:description) ? job_constantized.description : ""
end

#empty?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/sidekiq-web-workers/job_presenter.rb', line 27

def empty?
  job_constantized.blank?
end

#escaped_nameObject



31
32
33
# File 'lib/sidekiq-web-workers/job_presenter.rb', line 31

def escaped_name
  CGI.escape worker_name
end

#include?(text) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/sidekiq-web-workers/job_presenter.rb', line 35

def include?(text)
  return false unless job_constantized
  downcased_text = text.downcase
  worker_name.downcase.include?(downcased_text) ||
    description.downcase.include?(downcased_text)
end

#job_constantizedObject



21
22
23
24
25
# File 'lib/sidekiq-web-workers/job_presenter.rb', line 21

def job_constantized
  @worker_name.constantize
rescue
  nil
end

#method_argumentsObject



12
13
14
15
16
17
18
19
# File 'lib/sidekiq-web-workers/job_presenter.rb', line 12

def method_arguments
  return [] unless job_constantized
  job_constantized.new.method(:perform).parameters
  #[[:opt, :param_name], [:req, :param_name]] empty if no params
  # for named parameters this can be [[:key, :param_name], [:keyreq, :param_name]]
  # key means optional keyreq means required but sidekiq does not s
  # sidekiq doesn't support named args tho https://github.com/mperham/sidekiq/issues/2372
end