Sha256: 36196b4fb070cb733499da885cc11dcd8bb7754f8e184b97e7d1734eb579c49c

Contents?: true

Size: 1.05 KB

Versions: 89

Compression:

Stored size: 1.05 KB

Contents

module RailsOps
  # This class extends ActiveJob::Job and, when subclassed, allows to link
  # common job classes to operations. When defining a Job, just extend this
  # class and use the static `op` method in order to hook it to a specific
  # operation. The `perform` method will then automatically run the operation
  # via its `run!` method and with the given params.
  class HookedJob < ActiveJob::Base
    class_attribute :operation_class

    # Set an operation class this job shall be hooked with. This is mandatory
    # unless you override the `perform` method (which would be an abuse of this
    # class anyways).
    def self.op(klass)
      self.operation_class = klass
    end

    # This method is called by the ActiveJob framework and solely executes the
    # hooked operation's `run!` method. If no operation has been hooked (use the
    # static method `op` for that), it will raise an exception.
    def perform(params = {})
      fail 'This job is not hooked to any operation.' unless operation_class
      operation_class.run!(params)
    end
  end
end

Version data entries

89 entries across 89 versions & 1 rubygems

Version Path
rails_ops-1.5.8 lib/rails_ops/hooked_job.rb
rails_ops-1.5.7 lib/rails_ops/hooked_job.rb
rails_ops-1.5.6 lib/rails_ops/hooked_job.rb
rails_ops-1.5.5 lib/rails_ops/hooked_job.rb
rails_ops-1.5.4 lib/rails_ops/hooked_job.rb
rails_ops-1.5.0 lib/rails_ops/hooked_job.rb
rails_ops-1.4.8 lib/rails_ops/hooked_job.rb
rails_ops-1.4.7 lib/rails_ops/hooked_job.rb
rails_ops-1.4.6 lib/rails_ops/hooked_job.rb
rails_ops-1.4.5 lib/rails_ops/hooked_job.rb
rails_ops-1.4.4 lib/rails_ops/hooked_job.rb
rails_ops-1.4.3 lib/rails_ops/hooked_job.rb
rails_ops-1.4.2 lib/rails_ops/hooked_job.rb
rails_ops-1.0.17.1 lib/rails_ops/hooked_job.rb
rails_ops-1.4.1 lib/rails_ops/hooked_job.rb
rails_ops-1.4.0 lib/rails_ops/hooked_job.rb
rails_ops-1.3.0 lib/rails_ops/hooked_job.rb
rails_ops-1.2.3 lib/rails_ops/hooked_job.rb
rails_ops-1.2.2 lib/rails_ops/hooked_job.rb
rails_ops-1.2.1 lib/rails_ops/hooked_job.rb