Class: Faraday::Options

### Home Classes Methods

### In Files

- lib/faraday/options.rb

### Parent

Struct

### Methods

- ::attribute_options
- ::fetch_error_class
- ::from
- ::inherited
- ::memoized
- ::memoized_attributes
- ::options
- ::options_for
- #[]
- #clear
- #delete
- #each
- #each_key
- #each_value
- #empty?
- #fetch
- #has_key?
- #has_value?
- #inspect
- #key?
- #keys
- #merge
- #merge!
- #symbolized_key_set
- #to_hash
- #update
- #value?
- #values_at

### Class/Module Index

Quicksearch

- Faraday
- Faraday::Adapter
- Faraday::Adapter::EMHttp
- Faraday::Adapter::EMHttp::Manager
- Faraday::Adapter::EMHttp::Options
- Faraday::Adapter::EMSynchrony
- Faraday::Adapter::EMSynchrony::ParallelManager
- Faraday::Adapter::Excon
- Faraday::Adapter::HTTPClient
- Faraday::Adapter::NetHttp
- Faraday::Adapter::NetHttpPersistent
- Faraday::Adapter::Parallelism
- Faraday::Adapter::Patron
- Faraday::Adapter::Rack
- Faraday::Adapter::Test
- Faraday::Adapter::Test::Stub
- Faraday::Adapter::Test::Stubs
- Faraday::Adapter::Test::Stubs::NotFound
- Faraday::Adapter::Typhoeus
- Faraday::AutoloadHelper
- Faraday::ClientError
- Faraday::CompositeReadIO
- Faraday::Connection
- Faraday::ConnectionFailed
- Faraday::ConnectionOptions
- Faraday::Env
- Faraday::Error
- Faraday::FlatParamsEncoder
- Faraday::Middleware
- Faraday::MiddlewareRegistry
- Faraday::MissingDependency
- Faraday::NestedParamsEncoder
- Faraday::Options
- Faraday::ParsingError
- Faraday::ProxyOptions
- Faraday::RackBuilder
- Faraday::RackBuilder::Handler
- Faraday::RackBuilder::StackLocked
- Faraday::Request
- Faraday::Request::Authorization
- Faraday::Request::BasicAuthentication
- Faraday::Request::Instrumentation
- Faraday::Request::Instrumentation::Options
- Faraday::Request::Multipart
- Faraday::Request::Retry
- Faraday::Request::Retry::Options
- Faraday::Request::TokenAuthentication
- Faraday::Request::UrlEncoded
- Faraday::RequestOptions
- Faraday::ResourceNotFound
- Faraday::Response
- Faraday::Response::Logger
- Faraday::Response::Middleware
- Faraday::Response::RaiseError
- Faraday::SSLError
- Faraday::SSLOptions
- Faraday::TimeoutError
- Faraday::Utils
- Faraday::Utils::Headers
- Faraday::Utils::ParamsHash
- EmHttpSslPatch
- Object

No matching classes.

# Faraday::Options

Subclasses Struct with some special helpers for converting from a Hash to a Struct.

### Public Class Methods

attribute_options() click to toggle source

Internal

    # File lib/faraday/options.rb, line 148
    def self.attribute_options
      @attribute_options ||= {}
    end

fetch_error_class() click to toggle source

    # File lib/faraday/options.rb, line 182
    def self.fetch_error_class
      @fetch_error_class ||= if Object.const_defined?(:KeyError)
        ::KeyError
      else
        ::IndexError
      end
    end

from(value) click to toggle source

Public

    # File lib/faraday/options.rb, line 6
    def self.from(value)
      value ? new.update(value) : new
    end

inherited(subclass) click to toggle source

    # File lib/faraday/options.rb, line 176
    def self.inherited(subclass)
      super
      subclass.attribute_options.update(attribute_options)
      subclass.memoized_attributes.update(memoized_attributes)
    end

memoized(key) click to toggle source

    # File lib/faraday/options.rb, line 152
    def self.memoized(key)
      memoized_attributes[key.to_sym] = Proc.new
      class_eval         def #{key}() self[:#{key}]; end, __FILE__, __LINE__ + 1
    end

memoized_attributes() click to toggle source

    # File lib/faraday/options.rb, line 159
    def self.memoized_attributes
      @memoized_attributes ||= {}
    end

options(mapping) click to toggle source

Internal

    # File lib/faraday/options.rb, line 138
    def self.options(mapping)
      attribute_options.update(mapping)
    end

options_for(key) click to toggle source

Internal

    # File lib/faraday/options.rb, line 143
    def self.options_for(key)
      attribute_options[key]
    end

### Public Instance Methods

[](key) click to toggle source

    # File lib/faraday/options.rb, line 163
    def [](key)
      key = key.to_sym
      if method = self.class.memoized_attributes[key]
        super(key) || (self[key] = instance_eval(&method))
      else
        super
      end
    end

clear() click to toggle source

Public

    # File lib/faraday/options.rb, line 46
    def clear
      members.each { |member| delete(member) }
    end

delete(key) click to toggle source

Public

    # File lib/faraday/options.rb, line 39
    def delete(key)
      value = send(key)
      send("#{key}=", nil)
      value
    end

each() click to toggle source

Public

    # File lib/faraday/options.rb, line 11
    def each
      return to_enum(:each) unless block_given?
      members.each do |key|
        yield(key.to_sym, send(key))
      end
    end

each_key() click to toggle source

Public

    # File lib/faraday/options.rb, line 86
    def each_key
      return to_enum(:each_key) unless block_given?
      keys.each do |key|
        yield(key)
      end
    end

each_value() click to toggle source

Public

    # File lib/faraday/options.rb, line 101
    def each_value
      return to_enum(:each_value) unless block_given?
      values.each do |value|
        yield(value)
      end
    end

empty?() click to toggle source

Public

    # File lib/faraday/options.rb, line 81
    def empty?
      keys.empty?
    end

fetch(key, *args) click to toggle source

Public

    # File lib/faraday/options.rb, line 56
    def fetch(key, *args)
      unless symbolized_key_set.include?(key.to_sym)
        key_setter = "#{key}="
        if args.size > 0
          send(key_setter, args.first)
        elsif block_given?
          send(key_setter, Proc.new.call(key))
        else
          raise self.class.fetch_error_class, "key not found: #{key.inspect}"
        end
      end
      send(key)
    end

has_key?(key) click to toggle source
Alias for: key?
has_value?(value) click to toggle source
Alias for: value?
inspect() click to toggle source

Internal

    # File lib/faraday/options.rb, line 126
    def inspect
      values = []
      members.each do |member|
        value = send(member)
        values << "#{member}=#{value.inspect}" if value
      end
      values = values.empty? ? ' (empty)' : (' ' << values.join(", "))

      %(#<#{self.class}#{values}>)
    end

key?(key) click to toggle source

Public

    # File lib/faraday/options.rb, line 94
    def key?(key)
      keys.include?(key)
    end

Also aliased as: has_key?
keys() click to toggle source

Public

    # File lib/faraday/options.rb, line 76
    def keys
      members.reject { |member| send(member).nil? }
    end

merge(value) click to toggle source

Public

    # File lib/faraday/options.rb, line 51
    def merge(value)
      dup.update(value)
    end

merge!(obj) click to toggle source
Alias for: update
symbolized_key_set() click to toggle source

    # File lib/faraday/options.rb, line 172
    def symbolized_key_set
      @symbolized_key_set ||= Set.new(keys.map { |k| k.to_sym })
    end

to_hash() click to toggle source

Public

    # File lib/faraday/options.rb, line 116
    def to_hash
      hash = {}
      members.each do |key|
        value = send(key)
        hash[key.to_sym] = value unless value.nil?
      end
      hash
    end

update(obj) click to toggle source

Public

    # File lib/faraday/options.rb, line 19
    def update(obj)
      obj.each do |key, value|
        if sub_options = self.class.options_for(key)
          value = sub_options.from(value) if value
        elsif Hash === value
          hash = {}
          value.each do |hash_key, hash_value|
            hash[hash_key] = hash_value
          end
          value = hash
        end

        self.send("#{key}=", value) unless value.nil?
      end
      self
    end

Also aliased as: merge!
value?(value) click to toggle source

Public

    # File lib/faraday/options.rb, line 109
    def value?(value)
      values.include?(value)
    end

Also aliased as: has_value?
values_at(*keys) click to toggle source

Public

    # File lib/faraday/options.rb, line 71
    def values_at(*keys)
      keys.map { |key| send(key) }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.