Class: Resque::UniqueByArity::Cop

Inherits:
Module
  • Object
show all
Defined in:
lib/resque/unique_by_arity/cop.rb

Instance Method Summary collapse

Constructor Details

#initialize(**config) ⇒ Cop

Returns a new instance of Cop.



4
5
6
# File 'lib/resque/unique_by_arity/cop.rb', line 4

def initialize(**config)
  @configuration = Resque::UniqueByArity::Configuration.new(**config)
end

Instance Method Details

#included(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/resque/unique_by_arity/cop.rb', line 7

def included(base)
  return unless @configuration
  @configuration.base_klass_name = base.to_s
  @configuration.validate
  base.send(:extend, Resque::UniqueByArity)
  base.uniqueness_config_reset(@configuration.dup)

  # gem is resque_solo, which is a rewrite of resque-loner
  # see: https://github.com/neighborland/resque_solo
  # defines a redis_key method, which we have to override.
  base.send(:include, Resque::Plugins::UniqueJob) if @configuration.unique_in_queue || @configuration.unique_across_queues

  # gem is resque-unique_at_runtime, which is a rewrite of resque-lonely_job
  # see: https://github.com/pboling/resque-unique_at_runtime
  base.send(:extend, Resque::Plugins::UniqueAtRuntime) if @configuration.unique_at_runtime

  uniqueness_cop_module = Resque::UniqueByArity::CopModulizer.to_mod(@configuration)
  # This will override methods from both plugins above, if configured for both
  base.send(:extend, uniqueness_cop_module)

  base.include Resque::UniqueByArity::Validation unless @configuration.skip_arity_validation?
end