Module: Resque::Plugin

Extended by:
Plugin
Included in:
Plugin
Defined in:
lib/resque_unit/plugin.rb

Constant Summary collapse

LintError =
Class.new(RuntimeError)

Instance Method Summary collapse

Instance Method Details

#after_enqueue_hooks(job) ⇒ Object

Given an object, returns a list ‘after_enqueue` hook names.



51
52
53
# File 'lib/resque_unit/plugin.rb', line 51

def after_enqueue_hooks(job)
  job.methods.grep(/^after_enqueue/).sort
end

#after_hooks(job) ⇒ Object

Given an object, returns a list ‘after_perform` hook names.



41
42
43
# File 'lib/resque_unit/plugin.rb', line 41

def after_hooks(job)
  job.methods.grep(/^after_perform/).sort
end

#around_hooks(job) ⇒ Object

Given an object, returns a list ‘around_perform` hook names.



36
37
38
# File 'lib/resque_unit/plugin.rb', line 36

def around_hooks(job)
  job.methods.grep(/^around_perform/).sort
end

#before_enqueue_hooks(job) ⇒ Object

Given an object, returns a list ‘before_enqueue` hook names.



56
57
58
# File 'lib/resque_unit/plugin.rb', line 56

def before_enqueue_hooks(job)
  job.methods.grep(/^before_enqueue/).sort
end

#before_hooks(job) ⇒ Object

Given an object, returns a list ‘before_perform` hook names.



31
32
33
# File 'lib/resque_unit/plugin.rb', line 31

def before_hooks(job)
  job.methods.grep(/^before_perform/).sort
end

#failure_hooks(job) ⇒ Object

Given an object, returns a list ‘on_failure` hook names.



46
47
48
# File 'lib/resque_unit/plugin.rb', line 46

def failure_hooks(job)
  job.methods.grep(/^on_failure/).sort
end

#lint(plugin) ⇒ Object

Ensure that your plugin conforms to good hook naming conventions.

Resque::Plugin.lint(MyResquePlugin)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/resque_unit/plugin.rb', line 14

def lint(plugin)
  hooks = before_hooks(plugin) + around_hooks(plugin) + after_hooks(plugin)

  hooks.each do |hook|
    if hook =~ /perform$/
      raise LintError, "#{plugin}.#{hook} is not namespaced"
    end
  end

  failure_hooks(plugin).each do |hook|
    if hook =~ /failure$/
      raise LintError, "#{plugin}.#{hook} is not namespaced"
    end
  end
end