Sha256: 6f786dd93071baa059868e128230880fadd45b3014a8110c2176829d5a199404

Contents?: true

Size: 1.26 KB

Versions: 26

Compression:

Stored size: 1.26 KB

Contents

module Inferno
  module DSL
    # This module contains the HTTP DSL available to test writers.
    class HTTPClientBuilder
      attr_accessor :runnable

      # @private
      def build(runnable, block)
        self.runnable = runnable
        instance_exec(self, &block)

        params = { url: url }
        params.merge!(headers: headers) if headers

        Faraday.new(params)
      end

      # Define the base url for an HTTP client. A string or symbol can be
      # provided. A string is interpreted as a url. A symbol is interpreted as
      # the name of an input to the Runnable.
      #
      # @param url [String, Symbol]
      # @return [void]
      def url(url = nil)
        @url ||=
          if url.is_a? Symbol
            runnable.send(url)
          else
            url
          end
      end

      # Define custom headers for a client
      #
      # @param headers [Hash]
      # @return [void]
      def headers(headers = nil)
        @headers ||= headers
      end

      # @private
      def method_missing(name, *args, &block)
        return runnable.call(name, *args, &block) if runnable.respond_to? name

        super
      end

      # @private
      def respond_to_missing?(name)
        runnable.respond_to?(name) || super
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
inferno_core-0.3.5 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.3.4 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.3.3 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.3.2 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.3.1 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.3.0 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.3.0.rc1 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.2.0 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.2.0.rc4 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.2.0.rc3 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.2.0.rc2 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.2.0.rc1 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.1.4.pre lib/inferno/dsl/http_client_builder.rb
inferno_core-0.1.3 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.1.3.pre2 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.1.3.pre lib/inferno/dsl/http_client_builder.rb
inferno_core-0.1.2 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.1.2.pre lib/inferno/dsl/http_client_builder.rb
inferno_core-0.1.1 lib/inferno/dsl/http_client_builder.rb
inferno_core-0.1.1.pre lib/inferno/dsl/http_client_builder.rb