module Seahorse::Client::HandlerBuilder

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}.

Public Instance Methods

handle(*args, &block) click to toggle source
# File lib/seahorse/client/handler_builder.rb, line 24
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
Also aliased as: handler
handle_request(*args, &block) click to toggle source
# File lib/seahorse/client/handler_builder.rb, line 9
def handle_request(*args, &block)
  handler(*args) do |context|
    block.call(context)
    @handler.call(context)
  end
end
handle_response(*args, &block) click to toggle source
# File lib/seahorse/client/handler_builder.rb, line 16
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
handler(*args, &block)
Alias for: handle
handler_for(name = nil, &block) click to toggle source

@api private

# File lib/seahorse/client/handler_builder.rb, line 32
def handler_for(name = nil, &block)
  if name
    const_set(name, new_handler(block))
  else
    new_handler(block)
  end
end
new_handler(block) click to toggle source

@api private

# File lib/seahorse/client/handler_builder.rb, line 41
def new_handler(block)
  Class.new(Handler) do
    define_method(:call, &block)
  end
end