Sha256: 0614f083fde632240fb10e6cb3681051ebae6151a546cf314861f42aea163ccb

Contents?: true

Size: 1.23 KB

Versions: 190

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Seahorse
  module Client

    # This module provides the ability to add handlers to a class or
    # module.  The including class or extending module must respond to
    # `#handlers`, returning a {HandlerList}.
    module HandlerBuilder

      def handle_request(*args, &block)
        handler(*args) do |context|
          block.call(context)
          @handler.call(context)
        end
      end

      def handle_response(*args, &block)
        handler(*args) do |context|
          resp = @handler.call(context)
          block.call(resp) if resp.context.http_response.status_code > 0
          resp
        end
      end

      def handle(*args, &block)
        options = args.last.is_a?(Hash) ? args.pop : {}
        handler_class = block ? handler_for(*args, &block) : args.first
        handlers.add(handler_class, options)
      end
      alias handler handle

      # @api private
      def handler_for(name = nil, &block)
        if name
          const_set(name, new_handler(block))
        else
          new_handler(block)
        end
      end

      # @api private
      def new_handler(block)
        Class.new(Handler) do
          define_method(:call, &block)
        end
      end

    end
  end
end

Version data entries

190 entries across 190 versions & 1 rubygems

Version Path
aws-sdk-core-3.214.0 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.213.0 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.212.0 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.211.0 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.210.0 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.209.1 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.209.0 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.208.0 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.207.0 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.206.0 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.205.0 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.204.0 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.203.0 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.202.2 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.202.1 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.202.0 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.201.5 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.201.4 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.201.3 lib/seahorse/client/handler_builder.rb
aws-sdk-core-3.201.2 lib/seahorse/client/handler_builder.rb