Class: HTTP::Options
- Inherits:
-
Object
- Object
- HTTP::Options
- Defined in:
- lib/http/options.rb
Class Attribute Summary collapse
-
.available_features ⇒ Object
readonly
Returns the value of attribute available_features.
-
.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
- .defined_options ⇒ Object
-
.new(options = {}) ⇒ Object
rubocop:disable Style/OptionHash.
- .register_feature(name, impl) ⇒ Object
Instance Method Summary collapse
- #dup {|dupped| ... } ⇒ Object
- #feature(name) ⇒ Object
- #features=(features) ⇒ Object
- #follow=(value) ⇒ Object
-
#initialize(options = {}) ⇒ Options
constructor
rubocop:disable Style/OptionHash.
- #merge(other) ⇒ Object
- #persistent=(value) ⇒ Object
- #persistent? ⇒ Boolean
- #to_hash ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Options
rubocop:disable Style/OptionHash
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/http/options.rb', line 53 def initialize( = {}) # rubocop:disable Style/OptionHash 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() opts_w_defaults[:headers] = HTTP::Headers.coerce(opts_w_defaults[:headers]) opts_w_defaults.each { |(k, v)| self[k] = v } end |
Class Attribute Details
.available_features ⇒ Object (readonly)
Returns the value of attribute available_features.
19 20 21 |
# File 'lib/http/options.rb', line 19 def available_features @available_features end |
.default_socket_class ⇒ Object
Returns the value of attribute default_socket_class.
18 19 20 |
# File 'lib/http/options.rb', line 18 def default_socket_class @default_socket_class end |
.default_ssl_socket_class ⇒ Object
Returns the value of attribute default_ssl_socket_class.
18 19 20 |
# File 'lib/http/options.rb', line 18 def default_ssl_socket_class @default_ssl_socket_class end |
.default_timeout_class ⇒ Object
Returns the value of attribute default_timeout_class.
18 19 20 |
# File 'lib/http/options.rb', line 18 def default_timeout_class @default_timeout_class end |
Class Method Details
.defined_options ⇒ Object
26 27 28 |
# File 'lib/http/options.rb', line 26 def @defined_options ||= [] end |
.new(options = {}) ⇒ Object
rubocop:disable Style/OptionHash
21 22 23 24 |
# File 'lib/http/options.rb', line 21 def new( = {}) # rubocop:disable Style/OptionHash return if .is_a?(self) super end |
.register_feature(name, impl) ⇒ Object
30 31 32 |
# File 'lib/http/options.rb', line 30 def register_feature(name, impl) @available_features[name] = impl end |
Instance Method Details
#dup {|dupped| ... } ⇒ Object
175 176 177 178 179 |
# File 'lib/http/options.rb', line 175 def dup dupped = super yield(dupped) if block_given? dupped end |
#feature(name) ⇒ Object
181 182 183 |
# File 'lib/http/options.rb', line 181 def feature(name) features[name] end |
#features=(features) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/http/options.rb', line 109 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 |
#follow=(value) ⇒ Object
132 133 134 135 136 137 138 139 140 |
# File 'lib/http/options.rb', line 132 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
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/http/options.rb', line 152 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
144 145 146 |
# File 'lib/http/options.rb', line 144 def persistent=(value) @persistent = value ? HTTP::URI.parse(value).origin : nil end |
#persistent? ⇒ Boolean
148 149 150 |
# File 'lib/http/options.rb', line 148 def persistent? !persistent.nil? end |
#to_hash ⇒ Object
168 169 170 171 172 173 |
# File 'lib/http/options.rb', line 168 def to_hash hash_pairs = self.class. . flat_map { |opt_name| [opt_name, send(opt_name)] } Hash[*hash_pairs] end |