Sha256: 87646e523f5b0ec2936ebfaebe4fcba9577fec3a5f01368e6e35659f3675dcbb

Contents?: true

Size: 1.2 KB

Versions: 1220

Compression:

Stored size: 1.2 KB

Contents

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

1,220 entries across 1,220 versions & 2 rubygems

Version Path
aws-sdk-core-2.11.632 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.631 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.630 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.629 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.628 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.627 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.626 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.625 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.624 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.623 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.622 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.621 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.620 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.619 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.618 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.617 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.616 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.615 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.614 lib/seahorse/client/handler_builder.rb
aws-sdk-core-2.11.613 lib/seahorse/client/handler_builder.rb