module ResqueAdmin::Plugin

Constants

LintError

Public Instance Methods

after_dequeue_hooks(job) click to toggle source

Given an object, returns a list `after_dequeue` hook names.

# File lib/resque_admin/plugin.rb, line 69
def after_dequeue_hooks(job)
  get_hook_names(job, 'after_dequeue')
end
after_enqueue_hooks(job) click to toggle source

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

# File lib/resque_admin/plugin.rb, line 59
def after_enqueue_hooks(job)
  get_hook_names(job, 'after_enqueue')
end
after_hooks(job) click to toggle source

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

# File lib/resque_admin/plugin.rb, line 49
def after_hooks(job)
  get_hook_names(job, 'after_perform')
end
around_hooks(job) click to toggle source

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

# File lib/resque_admin/plugin.rb, line 44
def around_hooks(job)
  get_hook_names(job, 'around_perform')
end
before_dequeue_hooks(job) click to toggle source

Given an object, returns a list `before_dequeue` hook names.

# File lib/resque_admin/plugin.rb, line 74
def before_dequeue_hooks(job)
  get_hook_names(job, 'before_dequeue')
end
before_enqueue_hooks(job) click to toggle source

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

# File lib/resque_admin/plugin.rb, line 64
def before_enqueue_hooks(job)
  get_hook_names(job, 'before_enqueue')
end
before_hooks(job) click to toggle source

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

# File lib/resque_admin/plugin.rb, line 39
def before_hooks(job)
  get_hook_names(job, 'before_perform')
end
failure_hooks(job) click to toggle source

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

# File lib/resque_admin/plugin.rb, line 54
def failure_hooks(job)
  get_hook_names(job, 'on_failure')
end
get_hook_names(job, hook_method_prefix) click to toggle source

Given an object, and a method prefix, returns a list of methods prefixed with that name (hook names).

# File lib/resque_admin/plugin.rb, line 33
def get_hook_names(job, hook_method_prefix)
  methods = (job.respond_to?(:hooks) && job.hooks) || job_methods(job)
  methods.select{|m| m.start_with?(hook_method_prefix)}.sort
end
job_methods(job) click to toggle source
# File lib/resque_admin/plugin.rb, line 27
def job_methods(job)
  @job_methods[job] ||= job.methods.collect{|m| m.to_s}
end
lint(plugin) click to toggle source

Ensure that your plugin conforms to good hook naming conventions.

ResqueAdmin::Plugin.lint(MyResquePlugin)
# File lib/resque_admin/plugin.rb, line 10
def lint(plugin)
  hooks = before_hooks(plugin) + around_hooks(plugin) + after_hooks(plugin)

  hooks.each do |hook|
    if hook.to_s.end_with?("perform")
      raise LintError, "#{plugin}.#{hook} is not namespaced"
    end
  end

  failure_hooks(plugin).each do |hook|
    if hook.to_s.end_with?("failure")
      raise LintError, "#{plugin}.#{hook} is not namespaced"
    end
  end
end