Class: HTTP::Options
- Inherits:
-
Object
- Object
- HTTP::Options
- Defined in:
- lib/http/options.rb
Class Attribute Summary collapse
-
.default_cache ⇒ Object
Returns the value of attribute default_cache.
-
.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
- #[](option) ⇒ Object
- #dup {|dupped| ... } ⇒ Object
- #follow=(value) ⇒ Object
-
#initialize(options = {}) ⇒ Options
constructor
A new instance of Options.
- #merge(other) ⇒ Object
- #persistent? ⇒ Boolean
- #to_hash ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Options
Returns a new instance of Options.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/http/options.rb', line 43 def initialize( = {}) defaults = {:response => :auto, :proxy => {}, :timeout_class => self.class.default_timeout_class, :timeout_options => {}, :socket_class => self.class.default_socket_class, :ssl_socket_class => self.class.default_ssl_socket_class, :ssl => {}, :cache => self.class.default_cache, :keep_alive_timeout => 5, :headers => {}} opts_w_defaults = defaults.merge() opts_w_defaults[:headers] = HTTP::Headers.coerce(opts_w_defaults[:headers]) opts_w_defaults.each do |(opt_name, opt_val)| self[opt_name] = opt_val end end |
Class Attribute Details
.default_cache ⇒ Object
Returns the value of attribute default_cache.
17 18 19 |
# File 'lib/http/options.rb', line 17 def default_cache @default_cache end |
.default_socket_class ⇒ Object
Returns the value of attribute default_socket_class.
16 17 18 |
# File 'lib/http/options.rb', line 16 def default_socket_class @default_socket_class end |
.default_ssl_socket_class ⇒ Object
Returns the value of attribute default_ssl_socket_class.
16 17 18 |
# File 'lib/http/options.rb', line 16 def default_ssl_socket_class @default_ssl_socket_class end |
.default_timeout_class ⇒ Object
Returns the value of attribute default_timeout_class.
17 18 19 |
# File 'lib/http/options.rb', line 17 def default_timeout_class @default_timeout_class end |
Class Method Details
.defined_options ⇒ Object
24 25 26 |
# File 'lib/http/options.rb', line 24 def @defined_options ||= [] end |
.new(options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/http/options.rb', line 19 def new( = {}) return if .is_a?(self) super end |
Instance Method Details
#[](option) ⇒ Object
97 98 99 |
# File 'lib/http/options.rb', line 97 def [](option) send(option) rescue nil end |
#dup {|dupped| ... } ⇒ Object
122 123 124 125 126 |
# File 'lib/http/options.rb', line 122 def dup dupped = super yield(dupped) if block_given? dupped end |
#follow=(value) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/http/options.rb', line 75 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 |
# File 'lib/http/options.rb', line 101 def merge(other) h1, h2 = to_hash, 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? ⇒ Boolean
93 94 95 |
# File 'lib/http/options.rb', line 93 def persistent? !persistent.nil? && persistent != "" end |
#to_hash ⇒ Object
115 116 117 118 119 120 |
# File 'lib/http/options.rb', line 115 def to_hash hash_pairs = self.class . .flat_map { |opt_name| [opt_name, self[opt_name]] } Hash[*hash_pairs] end |