module NxtHttpClient::ClientDsl
Public Instance Methods
after_fire(&block)
click to toggle source
# File lib/nxt_http_client/client_dsl.rb, line 28 def after_fire(&block) callbacks.register(:after, block) end
around_fire(&block)
click to toggle source
# File lib/nxt_http_client/client_dsl.rb, line 32 def around_fire(&block) callbacks.register(:around, block) end
before_fire(&block)
click to toggle source
# File lib/nxt_http_client/client_dsl.rb, line 24 def before_fire(&block) callbacks.register(:before, block) end
callbacks()
click to toggle source
# File lib/nxt_http_client/client_dsl.rb, line 40 def callbacks @callbacks ||= dup_option_from_ancestor(:@callbacks) { FireCallbacks.new } end
clear_fire_callbacks(*kinds)
click to toggle source
# File lib/nxt_http_client/client_dsl.rb, line 20 def clear_fire_callbacks(*kinds) callbacks.clear(*kinds) end
config()
click to toggle source
# File lib/nxt_http_client/client_dsl.rb, line 36 def config @config ||= dup_option_from_ancestor(:@config) { Config.new } end
configure(opts = {}, &block)
click to toggle source
# File lib/nxt_http_client/client_dsl.rb, line 3 def configure(opts = {}, &block) opts.each { |k, v| config.send(k, v) } config.tap { |d| block.call(d) } config end
log(&block)
click to toggle source
# File lib/nxt_http_client/client_dsl.rb, line 9 def log(&block) @logger ||= block || dup_option_from_ancestor(:@logger) return unless @logger.present? logger = @logger around_fire do |client, request, response_handler, fire| Logger.new(logger).call(client, request, response_handler, fire) end end
response_handler(handler = Undefined.new, &block)
click to toggle source
# File lib/nxt_http_client/client_dsl.rb, line 44 def response_handler(handler = Undefined.new, &block) if undefined?(handler) @response_handler ||= dup_option_from_ancestor(:@response_handler) { NxtHttpClient::ResponseHandler.new } else @response_handler = handler end @response_handler.configure(&block) if block_given? @response_handler end
Also aliased as: response_handler
Private Instance Methods
client_ancestors()
click to toggle source
# File lib/nxt_http_client/client_dsl.rb, line 59 def client_ancestors ancestors.select { |ancestor| ancestor <= NxtHttpClient::Client } end
dup_option_from_ancestor(name) { || ... }
click to toggle source
# File lib/nxt_http_client/client_dsl.rb, line 68 def dup_option_from_ancestor(name) result = option_from_ancestors(name).dup return result unless block_given? result || yield end
option_from_ancestors(name)
click to toggle source
# File lib/nxt_http_client/client_dsl.rb, line 63 def option_from_ancestors(name) client = client_ancestors.find { |c| c.instance_variable_get(name) } client && client.instance_variable_get(name) end
undefined?(value)
click to toggle source
# File lib/nxt_http_client/client_dsl.rb, line 75 def undefined?(value) value.is_a?(Undefined) end