Sha256: 484a1ad9a4c6dfc314a4c2dad1409dec1bfacb4dd0a1e018723dab324cc79b3c

Contents?: true

Size: 709 Bytes

Versions: 2

Compression:

Stored size: 709 Bytes

Contents

module BMC::SetupJobConcern
  extend ActiveSupport::Concern

  def perform(*)
    setup(*)
    call
  end

  def call
    raise NotImplementedError
  end

  class_methods do
    def setup_with(*attrs)
      attr_reader(*attrs)

      define_method(:setup) do |*args|
        if attrs.length != args.length
          message = "wrong number of arguments (given #{args.length}, expected #{attrs.length})"
          raise ArgumentError, message
        end

        attrs.length.times do |i|
          instance_variable_set(:"@#{attrs[i]}", args[i])
        end
      end
    end

    private :setup_with

    def setup(*args)
      new.tap { |instance| instance.setup(*args) }
    end
  end # class_methods
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bmc-1.6.1 app/jobs/concerns/bmc/setup_job_concern.rb
bmc-1.6.0 app/jobs/concerns/bmc/setup_job_concern.rb