Sha256: dd2ba559949b273a44ab57fee9f81d0a8de050282587c7a1eead72d558a4d700

Contents?: true

Size: 604 Bytes

Versions: 1

Compression:

Stored size: 604 Bytes

Contents

module Tennis
  class Action

    attr_reader :_receiver

    def initialize(receiver, delay: nil)
      @_receiver = receiver
      @delay = delay
      _create_methods!
    end

    private

    def _create_methods!
      _methods.each do |method|
        self.define_singleton_method(method) do |*arguments|
          _store(job: @_receiver, method: method, args: arguments)
        end
      end
    end

    def _methods
      @_receiver.class.instance_methods(false).map(&:to_s)
    end

    def _store(**kwargs)
      Tennis.config.backend.enqueue(**kwargs.merge(delay: @delay))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tennis-jobs-0.4.0 lib/tennis/action.rb