Sha256: ce0a2b99f36c725682563709f9c01cb012f4f5a39a8aa31154fa4848d3e414eb

Contents?: true

Size: 716 Bytes

Versions: 15

Compression:

Stored size: 716 Bytes

Contents

module BMC::SetupJobConcern
  extend ActiveSupport::Concern

  def perform(*args)
    setup(*args)
    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

15 entries across 15 versions & 1 rubygems

Version Path
bmc-1.4.3 app/jobs/concerns/bmc/setup_job_concern.rb
bmc-1.4.2 app/jobs/concerns/bmc/setup_job_concern.rb
bmc-1.4.1 app/jobs/concerns/bmc/setup_job_concern.rb
bmc-1.4.0 app/jobs/concerns/bmc/setup_job_concern.rb
bmc-1.3.5 app/jobs/concerns/bmc/setup_job_concern.rb
bmc-1.3.4 app/jobs/concerns/bmc/setup_job_concern.rb
bmc-1.3.3 app/jobs/concerns/bmc/setup_job_concern.rb
bmc-1.3.2 app/jobs/concerns/bmc/setup_job_concern.rb
bmc-1.3.1 app/jobs/concerns/bmc/setup_job_concern.rb
bmc-1.3.0 app/jobs/concerns/bmc/setup_job_concern.rb
bmc-1.2.1 app/jobs/concerns/bmc/setup_job_concern.rb
bmc-1.2.0 app/jobs/concerns/bmc/setup_job_concern.rb
bmc-1.1.0 app/jobs/concerns/bmc/setup_job_concern.rb
bmc-1.0.1 app/jobs/concerns/bmc/setup_job_concern.rb
bmc-1.0.0 app/jobs/concerns/bmc/setup_job_concern.rb