Class: HTTP::Options
- Inherits:
-
Object
- Object
- HTTP::Options
- Defined in:
- lib/http/options.rb
Class Attribute Summary collapse
-
.default_socket_class ⇒ Object
Returns the value of attribute default_socket_class.
-
.default_ssl_socket_class ⇒ Object
Returns the value of attribute default_ssl_socket_class.
-
.default_timeout_class ⇒ Object
Returns the value of attribute default_timeout_class.
Class Method Summary collapse
Instance Method Summary collapse
- #dup {|dupped| ... } ⇒ Object
- #follow=(value) ⇒ Object
-
#initialize(options = {}) ⇒ Options
constructor
A new instance of Options.
- #merge(other) ⇒ Object
- #persistent=(value) ⇒ Object
- #persistent? ⇒ Boolean
- #to_hash ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Options
Returns a new instance of Options.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/http/options.rb', line 40 def initialize( = {}) 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() opts_w_defaults[:headers] = HTTP::Headers.coerce(opts_w_defaults[:headers]) opts_w_defaults.each { |(k, v)| self[k] = v } end |
Class Attribute Details
.default_socket_class ⇒ Object
Returns the value of attribute default_socket_class.
14 15 16 |
# File 'lib/http/options.rb', line 14 def default_socket_class @default_socket_class end |
.default_ssl_socket_class ⇒ Object
Returns the value of attribute default_ssl_socket_class.
14 15 16 |
# File 'lib/http/options.rb', line 14 def default_ssl_socket_class @default_ssl_socket_class end |
.default_timeout_class ⇒ Object
Returns the value of attribute default_timeout_class.
14 15 16 |
# File 'lib/http/options.rb', line 14 def default_timeout_class @default_timeout_class end |
Class Method Details
.defined_options ⇒ Object
21 22 23 |
# File 'lib/http/options.rb', line 21 def @defined_options ||= [] end |
.new(options = {}) ⇒ Object
16 17 18 19 |
# File 'lib/http/options.rb', line 16 def new( = {}) return if .is_a?(self) super end |
Instance Method Details
#dup {|dupped| ... } ⇒ Object
124 125 126 127 128 |
# File 'lib/http/options.rb', line 124 def dup dupped = super yield(dupped) if block_given? dupped end |
#follow=(value) ⇒ Object
84 85 86 87 88 89 90 91 |
# 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) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# 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) ⇒ Object
93 94 95 |
# File 'lib/http/options.rb', line 93 def persistent=(value) @persistent = value ? HTTP::URI.parse(value).origin : nil end |
#persistent? ⇒ Boolean
97 98 99 |
# File 'lib/http/options.rb', line 97 def persistent? !persistent.nil? end |
#to_hash ⇒ Object
117 118 119 120 121 122 |
# File 'lib/http/options.rb', line 117 def to_hash hash_pairs = self.class. . flat_map { |opt_name| [opt_name, send(opt_name)] } Hash[*hash_pairs] end |