Sha256: 5108cb5c2b1343c03921cf238c19d64022a5bf9226ae56cf9e3f8a17b7711ba7

Contents?: true

Size: 1.19 KB

Versions: 66

Compression:

Stored size: 1.19 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
  end
end

Version data entries

66 entries across 66 versions & 4 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.7.4 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.7.3 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.7.2 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.7.1 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.7.0 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.6.9 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.6.8 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.6.7 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.6.6 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.6.5 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.6.4 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.6.3 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.6.2 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.6.1 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.6.0 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.5.17 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.5.16 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.5.15 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb
classiccms-0.5.14 vendor/bundle/gems/resque-mongo-1.9.8.1/lib/resque/plugin.rb