Sha256: f29ea83bf6bd5cc83dc8fa174673d0b2628254ca2dcd4c3c78f8441f9fca1829

Contents?: true

Size: 986 Bytes

Versions: 7

Compression:

Stored size: 986 Bytes

Contents

# encoding: UTF-8
require 'active_support/concern'

module RocketJob
  module Plugins
    module Job
      # Allow each child job to set its own defaults
      module Defaults
        extend ActiveSupport::Concern

        included do
          # Copy parent job defaults
          def self.inherited(base)
            super
            @rocket_job_defaults.each { |block| base.rocket_job(&block) } if @rocket_job_defaults
          end

          # Override parent defaults
          def self.rocket_job(&block)
            (@rocket_job_defaults ||=[]) << block
          end

          private

          def self.rocket_job_defaults
            @rocket_job_defaults
          end

          # Apply defaults after creating the model but before applying values
          def rocket_job_set_defaults
            if defaults = self.class.rocket_job_defaults
              defaults.each { |block| block.call(self) }
            end
          end
        end

      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rocketjob-2.1.3 lib/rocket_job/plugins/job/defaults.rb
rocketjob-2.1.2 lib/rocket_job/plugins/job/defaults.rb
rocketjob-2.1.1 lib/rocket_job/plugins/job/defaults.rb
rocketjob-2.0.0 lib/rocket_job/plugins/job/defaults.rb
rocketjob-2.0.0.rc3 lib/rocket_job/plugins/job/defaults.rb
rocketjob-2.0.0.rc2 lib/rocket_job/plugins/job/defaults.rb
rocketjob-2.0.0.rc1 lib/rocket_job/plugins/job/defaults.rb