Sha256: cb39dedc839d183baf3b22c3d019a1cb3a9dd6a3a6bb660f0659306917240fbc

Contents?: true

Size: 1.34 KB

Versions: 27

Compression:

Stored size: 1.34 KB

Contents

module Resque
  module Plugin
    extend self

    LintError = Class.new(RuntimeError)

    # Ensure that your plugin conforms to good hook naming conventions.
    #
    #   Resque::Plugin.lint(MyResquePlugin)
    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

    # Given an object, returns a list `before_perform` hook names.
    def before_hooks(job)
      job.methods.grep(/^before_perform/).sort
    end

    # Given an object, returns a list `around_perform` hook names.
    def around_hooks(job)
      job.methods.grep(/^around_perform/).sort
    end

    # Given an object, returns a list `after_perform` hook names.
    def after_hooks(job)
      job.methods.grep(/^after_perform/).sort
    end

    # Given an object, returns a list `on_failure` hook names.
    def failure_hooks(job)
      job.methods.grep(/^on_failure/).sort
    end

    # Given an object, returns a list `after_enqueue` hook names.
    def after_enqueue_hooks(job)
      job.methods.grep(/^after_enqueue/).sort
    end
  end
end

Version data entries

27 entries across 27 versions & 4 rubygems

Version Path
mongo-resque-1.17.1 lib/resque/plugin.rb
nfo-resque-mongo-1.15.1 lib/resque/plugin.rb
resque-1.17.1 lib/resque/plugin.rb
resque-1.17.0 lib/resque/plugin.rb
resque-1.16.1 lib/resque/plugin.rb
resque-1.16.0 lib/resque/plugin.rb
nfo-resque-mongo-1.15.0 lib/resque/plugin.rb
resque-1.15.0 lib/resque/plugin.rb
resque-1.14.0 lib/resque/plugin.rb
resque-1.13.0 lib/resque/plugin.rb
resque-igo-1.12.8 lib/resque/plugin.rb
resque-1.11.0 lib/resque/plugin.rb
resque-1.12.0 lib/resque/plugin.rb
resque-igo-1.12.7 lib/resque/plugin.rb
resque-igo-1.12.6 lib/resque/plugin.rb
resque-igo-1.12.5 lib/resque/plugin.rb
resque-igo-1.12.4 lib/resque/plugin.rb
resque-igo-1.12.3 lib/resque/plugin.rb
resque-igo-1.12.2 lib/resque/plugin.rb
resque-igo-1.12.1 lib/resque/plugin.rb