Module: SidekiqAdhocJob::Strategy

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#module_namesObject (readonly)

Returns the value of attribute module_names.



11
12
13
# File 'lib/sidekiq_adhoc_job/strategy.rb', line 11

def module_names
  @module_names
end

#worker_klassesObject (readonly)

Returns the value of attribute worker_klasses.



11
12
13
# File 'lib/sidekiq_adhoc_job/strategy.rb', line 11

def worker_klasses
  @worker_klasses
end

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/sidekiq_adhoc_job/strategy.rb', line 3

def self.included(base)
  SidekiqAdhocJob.strategies << base

  base.extend ClassMethods
  base.class_eval do
  end
end

Instance Method Details

#allowed_namespace?(class_name, allowlist:) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/sidekiq_adhoc_job/strategy.rb', line 30

def allowed_namespace?(class_name, allowlist:)
  return true if allowlist.empty? || allowlist.include?('Module') # allow any namespace

  allowlist.any? { |prefix| class_name.start_with?(prefix) }
end

#initialize(module_names) ⇒ Object



15
16
17
18
# File 'lib/sidekiq_adhoc_job/strategy.rb', line 15

def initialize(module_names)
  @module_names = module_names
  @worker_klasses = {}
end

#loadObject



20
21
22
23
24
25
26
27
28
# File 'lib/sidekiq_adhoc_job/strategy.rb', line 20

def load
  ObjectSpace.each_object(Class).each do |klass|
    next unless klass

    if worker_class?(klass) && allowed_namespace?(klass.name, allowlist: module_names)
      @worker_klasses[worker_path_name(klass.name)] = klass
    end
  end
end

#worker_path_name(worker_name) ⇒ Object



36
37
38
# File 'lib/sidekiq_adhoc_job/strategy.rb', line 36

def worker_path_name(worker_name)
  Utils::String.underscore(worker_name).gsub('/', '_')
end