Sha256: b40e67eb055b8255de48b0c4ff84c202a0accf3aa42f996a5b50143b4f1891b5

Contents?: true

Size: 1.52 KB

Versions: 5

Compression:

Stored size: 1.52 KB

Contents

module Manticore
  class Client
    module ProxiesInterface
      def respond_with(stubs)
        StubProxy.new(self, stubs)
      end

      # Causes the next request to be made asynchronously
      def async
        AsyncProxy.new(self)
      end

      # Causes the next request to be made immediately in the background
      def background
        BackgroundProxy.new(self)
      end
    end

    class BaseProxy
      include ProxiesInterface
      def initialize(client)
        @client = client
      end
    end

    class AsyncProxy < BaseProxy
      %w(get put head post delete options patch).each do |func|
        define_method func do |url, options = {}, &block|
          @client.send(func, url, options.merge(async: true), &block)
        end
      end
    end

    class StubProxy < BaseProxy
      def initialize(client, stubs)
        super(client)
        @stubs = stubs
      end

      %w(get put head post delete options patch).each do |func|
        define_method func do |url, options = {}, &block|
          @client.stub(url, @stubs)
          @client.send(func, url, options, &block).complete { @client.unstub url }
        end
      end
    end

    class BackgroundProxy < BaseProxy
      %w(get put head post delete options patch).each do |func|
        define_method func do |url, options = {}, &block|
          request = @client.send(func, url, options.merge(async: true), &block)
          @client.executor.java_method(:submit, [java.util.concurrent.Callable.java_class]).call request
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
manticore-0.4.4-java lib/manticore/client/proxies.rb
manticore-0.4.3-java lib/manticore/client/proxies.rb
manticore-0.4.2-java lib/manticore/client/proxies.rb
manticore-0.4.1-java lib/manticore/client/proxies.rb
manticore-0.4.0-java lib/manticore/client/proxies.rb