class HTTP::Options
Attributes
Public Class Methods
Source
# File lib/http/options.rb, line 23 def defined_options @defined_options ||= [] end
Source
# File lib/http/options.rb, line 19 def new(options = {}) options.is_a?(self) ? options : super end
Calls superclass method
Source
# File lib/http/options.rb, line 50 def initialize(options = {}) defaults = { :response => :auto, :proxy => {}, :timeout_class => self.class.default_timeout_class, :timeout_options => {}, :socket_class => self.class.default_socket_class, :nodelay => false, :ssl_socket_class => self.class.default_ssl_socket_class, :ssl => {}, :keep_alive_timeout => 5, :headers => {}, :cookies => {}, :encoding => nil, :features => {} } opts_w_defaults = defaults.merge(options) opts_w_defaults[:headers] = HTTP::Headers.coerce(opts_w_defaults[:headers]) opts_w_defaults.each { |(k, v)| self[k] = v } end
Source
# File lib/http/options.rb, line 27 def register_feature(name, impl) @available_features[name] = impl end
Protected Class Methods
Source
# File lib/http/options.rb, line 33 def def_option(name, reader_only: false, &interpreter) defined_options << name.to_sym interpreter ||= ->(v) { v } if reader_only attr_reader name else attr_accessor name protected :"#{name}=" end define_method(:"with_#{name}") do |value| dup { |opts| opts.send(:"#{name}=", instance_exec(value, &interpreter)) } end end
Public Instance Methods
Source
# File lib/http/options.rb, line 172 def dup dupped = super yield(dupped) if block_given? dupped end
Calls superclass method
Source
# File lib/http/options.rb, line 106 def features=(features) @features = features.each_with_object({}) do |(name, opts_or_feature), h| h[name] = if opts_or_feature.is_a?(Feature) opts_or_feature else unless (feature = self.class.available_features[name]) argument_error! "Unsupported feature: #{name}" end feature.new(**opts_or_feature) end end end
Source
# File lib/http/options.rb, line 129 def follow=(value) @follow = case when !value then nil when true == value then {} when value.respond_to?(:fetch) then value else argument_error! "Unsupported follow options: #{value}" end end
Source
# File lib/http/options.rb, line 149 def merge(other) h1 = to_hash h2 = other.to_hash merged = h1.merge(h2) do |k, v1, v2| case k when :headers v1.merge(v2) else v2 end end self.class.new(merged) end
Source
# File lib/http/options.rb, line 141 def persistent=(value) @persistent = value ? HTTP::URI.parse(value).origin : nil end
Source
# File lib/http/options.rb, line 165 def to_hash hash_pairs = self.class. defined_options. flat_map { |opt_name| [opt_name, send(opt_name)] } Hash[*hash_pairs] end
Protected Instance Methods
Source
# File lib/http/options.rb, line 184 def []=(option, val) send(:"#{option}=", val) end
Private Instance Methods
Source
# File lib/http/options.rb, line 190 def argument_error!(message) raise(Error, message, caller(1..-1)) end