lib/httpx/options.rb in httpx-0.12.0 vs lib/httpx/options.rb in httpx-0.13.0

- old
+ new

@@ -4,48 +4,29 @@ class Options WINDOW_SIZE = 1 << 14 # 16K MAX_BODY_THRESHOLD_SIZE = (1 << 10) * 112 # 112K class << self - def inherited(klass) - super - klass.instance_variable_set(:@defined_options, @defined_options.dup) - end - def new(options = {}) # let enhanced options go through return options if self == Options && options.class > self return options if options.is_a?(self) super end - def defined_options - @defined_options ||= [] - end - def def_option(name, &interpreter) - defined_options << name.to_sym - attr_reader name if interpreter define_method(:"#{name}=") do |value| return if value.nil? instance_variable_set(:"@#{name}", instance_exec(value, &interpreter)) end - - define_method(:"with_#{name}") do |value| - merge(name => instance_exec(value, &interpreter)) - end else attr_writer name - - define_method(:"with_#{name}") do |value| - merge(name => value) - end end protected :"#{name}=" end end @@ -67,10 +48,11 @@ :request_body_class => Class.new(Request::Body), :response_body_class => Class.new(Response::Body), :connection_class => Class.new(Connection), :transport => nil, :transport_options => nil, + :addresses => nil, :persistent => false, :resolver_class => (ENV["HTTPX_RESOLVER"] || :native).to_sym, :resolver_options => { cache: true }, } @@ -119,10 +101,14 @@ raise Error, "#{transport} is an unsupported transport type" unless IO.registry.key?(transport) transport end + def_option(:addresses) do |addrs| + Array(addrs) + end + %w[ params form json body ssl http2_settings request_class response_class headers_class request_body_class response_body_class connection_class io fallback_protocol debug debug_level transport_options resolver_class resolver_options persistent @@ -151,10 +137,12 @@ h2 = other.to_hash return self if h2.empty? h1 = to_hash + return self if h1 == h2 + merged = h1.merge(h2) do |k, v1, v2| case k when :headers, :ssl, :http2_settings, :timeout v1.merge(v2) else @@ -164,13 +152,13 @@ self.class.new(merged) end def to_hash - hash_pairs = self.class - .defined_options - .flat_map { |opt_name| [opt_name, send(opt_name)] } - Hash[*hash_pairs] + hash_pairs = instance_variables.map do |ivar| + [ivar[1..-1].to_sym, instance_variable_get(ivar)] + end + Hash[hash_pairs] end def initialize_dup(other) self.headers = other.headers.dup self.ssl = other.ssl.dup