Sha256: dedb2556dd10be8ac9b542c90c552dff39e279e82310d13f4cc5a50209a45795

Contents?: true

Size: 1.41 KB

Versions: 40

Compression:

Stored size: 1.41 KB

Contents

require "forwardable"

module Manticore
  # Mix-in that can be used to add Manticore functionality to arbitrary classes.
  # Its primary purpose is to extend the Manticore module for one-shot usage.
  #
  # @example  Simple mix-in usage
  #     class Foo
  #       include Manticore::Facade
  #       include_http_client pool_size: 5
  #
  #       def latest_results
  #         Foo.get "http://some.com/url"
  #       end
  #     end
  module Facade
    # @private
    def self.included(other)
      other.send :extend, ClassMethods
    end

    module ClassMethods
      # Adds basic synchronous Manticore::Client functionality to the receiver.
      # @param  options Hash Options to be passed to the underlying shared client, if it has not been created yet.
      # @return nil
      def include_http_client(options = {}, &block)
        @__manticore_facade_options = [options, block]
        class << self
          extend Forwardable
          def_delegators "__manticore_facade", :get, :head, :put, :post, :delete, :options, :patch, :http
        end
        nil
      end

      private

      def __manticore_facade
        @manticore_facade ||= begin
          options, block = *@__manticore_facade_options
          if shared_pool = options.delete(:shared_pool)
            Manticore.send(:__manticore_facade)
          else
            Manticore::Client.new(options, &block)
          end
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 5 rubygems

Version Path
manticore-0.9.1-java lib/manticore/facade.rb
manticore-0.9.0-java lib/manticore/facade.rb
manticore-0.8.0-java lib/manticore/facade.rb
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/lib/manticore/facade.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/lib/manticore/facade.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/lib/manticore/facade.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/lib/manticore/facade.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/lib/manticore/facade.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/lib/manticore/facade.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/lib/manticore/facade.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.7.1-java/lib/manticore/facade.rb
manticore-0.7.1-java lib/manticore/facade.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/lib/manticore/facade.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/lib/manticore/facade.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/lib/manticore/facade.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/lib/manticore/facade.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/lib/manticore/facade.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/lib/manticore/facade.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/lib/manticore/facade.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/manticore-0.6.4-java/lib/manticore/facade.rb