lib/httpx/chainable.rb in httpx-1.2.0 vs lib/httpx/chainable.rb in httpx-1.2.1

- old
+ new

@@ -1,45 +1,53 @@ # frozen_string_literal: true module HTTPX + # Session mixin, implements most of the APIs that the users call. + # delegates to a default session when extended. module Chainable %w[head get post put delete trace options connect patch].each do |meth| class_eval(<<-MOD, __FILE__, __LINE__ + 1) def #{meth}(*uri, **options) # def get(*uri, **options) request("#{meth.upcase}", uri, **options) # request("GET", uri, **options) end # end MOD end + # delegates to the default session (see HTTPX::Session#request). def request(*args, **options) branch(default_options).request(*args, **options) end def accept(type) with(headers: { "accept" => String(type) }) end + # delegates to the default session (see HTTPX::Session#wrap). def wrap(&blk) branch(default_options).wrap(&blk) end + # returns a new instance loaded with the +pl+ plugin and +options+. def plugin(pl, options = nil, &blk) klass = is_a?(S) ? self.class : Session klass = Class.new(klass) klass.instance_variable_set(:@default_options, klass.default_options.merge(default_options)) klass.plugin(pl, options, &blk).new end + # returns a new instance loaded with +options+. def with(options, &blk) branch(default_options.merge(options), &blk) end private + # returns default instance of HTTPX::Options. def default_options @options || Session.default_options end + # returns a default instance of HTTPX::Session. def branch(options, &blk) return self.class.new(options, &blk) if is_a?(S) Session.new(options, &blk) end