Module: Seahorse::Client::HandlerBuilder
Overview
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.
Instance Method Summary collapse
- #handle(*args, &block) ⇒ Object (also: #handler)
- #handle_request(*args, &block) ⇒ Object
- #handle_response(*args, &block) ⇒ Object
- #handler_for(name = nil, &block) ⇒ Object private
- #new_handler(block) ⇒ Object private
Instance Method Details
#handle(*args, &block) ⇒ Object Also known as: handler
26 27 28 29 30 |
# File 'lib/seahorse/client/handler_builder.rb', line 26 def handle(*args, &block) = args.last.is_a?(Hash) ? args.pop : {} handler_class = block ? handler_for(*args, &block) : args.first handlers.add(handler_class, ) end |
#handle_request(*args, &block) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/seahorse/client/handler_builder.rb', line 11 def handle_request(*args, &block) handler(*args) do |context| block.call(context) @handler.call(context) end end |
#handle_response(*args, &block) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/seahorse/client/handler_builder.rb', line 18 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_for(name = nil, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 37 38 39 40 |
# File 'lib/seahorse/client/handler_builder.rb', line 34 def handler_for(name = nil, &block) if name const_set(name, new_handler(block)) else new_handler(block) end end |
#new_handler(block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 46 47 |
# File 'lib/seahorse/client/handler_builder.rb', line 43 def new_handler(block) Class.new(Handler) do define_method(:call, &block) end end |