class HTTP::Options
Attributes
default_socket_class[RW]
default_ssl_socket_class[RW]
default_timeout_class[RW]
Public Class Methods
defined_options()
click to toggle source
# File lib/http/options.rb, line 21 def defined_options @defined_options ||= [] end
new(options = {})
click to toggle source
Calls superclass method
# File lib/http/options.rb, line 16 def new(options = {}) return options if options.is_a?(self) super end
new(options = {})
click to toggle source
# File lib/http/options.rb, line 40 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 } 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
Protected Class Methods
def_option(name, &interpreter)
click to toggle source
# File lib/http/options.rb, line 27 def def_option(name, &interpreter) defined_options << name.to_sym interpreter ||= lambda { |v| v } attr_accessor name protected :"#{name}=" define_method(:"with_#{name}") do |value| dup { |opts| opts.send(:"#{name}=", instance_exec(value, &interpreter)) } end end
Public Instance Methods
dup() { |dupped| ... }
click to toggle source
Calls superclass method
# File lib/http/options.rb, line 124 def dup dupped = super yield(dupped) if block_given? dupped end
follow=(value)
click to toggle source
# File lib/http/options.rb, line 84 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
merge(other)
click to toggle source
# File lib/http/options.rb, line 101 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
persistent=(value)
click to toggle source
# File lib/http/options.rb, line 93 def persistent=(value) @persistent = value ? HTTP::URI.parse(value).origin : nil end
persistent?()
click to toggle source
# File lib/http/options.rb, line 97 def persistent? !persistent.nil? end
to_hash()
click to toggle source
# File lib/http/options.rb, line 117 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
[]=(option, val)
click to toggle source
# File lib/http/options.rb, line 132 def []=(option, val) send(:"#{option}=", val) end
Private Instance Methods
argument_error!(message)
click to toggle source
# File lib/http/options.rb, line 138 def argument_error!(message) raise(Error, message, caller[1..-1]) end