class Faraday::Options
a Struct.
Subclasses Struct with some special helpers for converting from a Hash to
def self.attribute_options
def self.attribute_options @attribute_options ||= {} end
def self.from(value)
def self.from(value) value ? new.update(value) : new end
def self.options(mapping)
def self.options(mapping) attribute_options.update(mapping) end
def self.options_for(key)
def self.options_for(key) attribute_options[key] end
def delete(key)
def delete(key) value = send(key) send("#{key}=", nil) value end
def each(&block)
def each(&block) members.each do |key| block.call key.to_sym, send(key) end end
def fetch(key, default = nil)
def fetch(key, default = nil) send(key) || send("#{key}=", default || (block_given? ? Proc.new.call : nil)) end
def inspect
def inspect values = [] members.each do |m| value = send(m) values << "#{m}=#{value.inspect}" if value end values = values.empty? ? ' (empty)' : (' ' << values.join(", ")) %(#<#{self.class}#{values}>) end
def keys
def keys members.reject { |m| send(m).nil? } end
def merge(value)
def merge(value) dup.update(value) end
def to_hash
def to_hash hash = {} members.each do |key| value = send(key) hash[key.to_sym] = value if value end hash end
def update(obj)
def update(obj) obj.each do |key, value| next unless value sub_options = self.class.options_for(key) if sub_options && value value = sub_options.from(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) end self end
def values_at(*keys)
def values_at(*keys) keys.map { |key| send(key) } end