Sha256: c97ae3f4e90858ab9f98d64e2688ed4f711762e0824ed05ba894e77e5153d6ac

Contents?: true

Size: 721 Bytes

Versions: 34

Compression:

Stored size: 721 Bytes

Contents

module Agilibox::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

34 entries across 34 versions & 1 rubygems

Version Path
agilibox-2.0.0 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.11.0 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.10.5 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.10.2 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.10.1 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.10.0 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.9.20 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.9.19 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.9.18 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.9.17 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.9.16 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.9.15 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.9.14 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.9.13 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.9.12 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.9.11 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.9.10 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.9.9 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.9.8 app/jobs/concerns/agilibox/setup_job_concern.rb
agilibox-1.9.7 app/jobs/concerns/agilibox/setup_job_concern.rb