Class: HTTP::Options

### Home Classes Methods

### In Files

- lib/http/options.rb

### Parent

Object

### Methods

- ::def_option
- ::defined_options
- ::new
- ::new
- #[]
- #[]=
- #dup
- #follow=
- #merge
- #persistent=
- #persistent?
- #to_hash

### Class/Module Index

Quicksearch

- HTTP
- HTTP::Cache
- HTTP::Cache::Headers
- HTTP::Cache::NullCache
- HTTP::Cache::NullLogger
- HTTP::CacheError
- HTTP::Chainable
- HTTP::Client
- HTTP::Connection
- HTTP::Error
- HTTP::Headers
- HTTP::Headers::Mixin
- HTTP::InvalidHeaderNameError
- HTTP::MimeType
- HTTP::MimeType::Adapter
- HTTP::MimeType::JSON
- HTTP::Options
- HTTP::Redirector
- HTTP::Redirector::EndlessRedirectError
- HTTP::Redirector::TooManyRedirectsError
- HTTP::Request
- HTTP::Request::Caching
- HTTP::Request::UnsupportedMethodError
- HTTP::Request::UnsupportedSchemeError
- HTTP::Request::Writer
- HTTP::RequestError
- HTTP::Response
- HTTP::Response::Body
- HTTP::Response::Caching
- HTTP::Response::IoBody
- HTTP::Response::Parser
- HTTP::Response::Status
- HTTP::Response::StringBody
- HTTP::ResponseError
- HTTP::StateError
- HTTP::Timeout
- HTTP::Timeout::Global
- HTTP::Timeout::Null
- HTTP::Timeout::PerOperation
- HTTP::TimeoutError
- HTTP::URI
- Object

No matching classes.

# HTTP::Options

### Attributes

default_cache[RW]
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 25
    def defined_options
      @defined_options ||= []
    end

new(options = {}) click to toggle source

    # File lib/http/options.rb, line 20
    def new(options = {})
      return options if options.is_a?(self)
      super
    end

new(options = {}) click to toggle source

    # File lib/http/options.rb, line 44
    def initialize(options = {})
      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 =>          {},
        :cookies =>          {}
      }

      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 31
    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

[](option) click to toggle source

    # File lib/http/options.rb, line 109
    def [](option)
      send(option) rescue nil
    end

dup() click to toggle source

    # File lib/http/options.rb, line 136
    def dup
      dupped = super
      yield(dupped) if block_given?
      dupped
    end

follow=(value) click to toggle source

    # File lib/http/options.rb, line 83
    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 113
    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 92
    def persistent=(value)
      @persistent = value ? HTTP::URI.parse(value).origin : nil
    end

persistent?() click to toggle source

    # File lib/http/options.rb, line 96
    def persistent?
      !persistent.nil?
    end

to_hash() click to toggle source

    # File lib/http/options.rb, line 129
    def to_hash
      hash_pairs = self.class.
                   defined_options.
                   flat_map { |opt_name| [opt_name, self[opt_name]] }
      Hash[*hash_pairs]
    end

### Protected Instance Methods

[]=(option, val) click to toggle source

    # File lib/http/options.rb, line 144
    def []=(option, val)
      send(:"#{option}=", val)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.