class Faraday::Options
Subclasses Struct with some special helpers for converting from a Hash to a Struct.
Public Class Methods
Source
# File lib/faraday/options.rb, line 170 def self.attribute_options @attribute_options ||= {} end
Internal
Source
# File lib/faraday/options.rb, line 208 def self.fetch_error_class @fetch_error_class ||= if Object.const_defined?(:KeyError) ::KeyError else ::IndexError end end
Source
# File lib/faraday/options.rb, line 8 def self.from(value) value ? new.update(value) : new end
Public
Source
# File lib/faraday/options.rb, line 202 def self.inherited(subclass) super subclass.attribute_options.update(attribute_options) subclass.memoized_attributes.update(memoized_attributes) end
Calls superclass method
Source
# File lib/faraday/options.rb, line 174 def self.memoized(key, &block) unless block_given? raise ArgumentError, '#memoized must be called with a block' end memoized_attributes[key.to_sym] = block class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{key}() self[:#{key}]; end RUBY end
Source
# File lib/faraday/options.rb, line 185 def self.memoized_attributes @memoized_attributes ||= {} end
Source
# File lib/faraday/options.rb, line 160 def self.options(mapping) attribute_options.update(mapping) end
Internal
Source
# File lib/faraday/options.rb, line 165 def self.options_for(key) attribute_options[key] end
Internal
Public Instance Methods
Source
# File lib/faraday/options.rb, line 189 def [](key) key = key.to_sym if (method = self.class.memoized_attributes[key]) super(key) || (self[key] = instance_eval(&method)) else super end end
Calls superclass method
Source
# File lib/faraday/options.rb, line 46 def clear members.each { |member| delete(member) } end
Public
Source
# File lib/faraday/options.rb, line 71 def deep_dup self.class.from(self) end
Public
Source
# File lib/faraday/options.rb, line 39 def delete(key) value = send(key) send("#{key}=", nil) value end
Public
Source
# File lib/faraday/options.rb, line 13 def each return to_enum(:each) unless block_given? members.each do |key| yield(key.to_sym, send(key)) end end
Public
Source
# File lib/faraday/options.rb, line 106 def each_key return to_enum(:each_key) unless block_given? keys.each do |key| yield(key) end end
Public
Source
# File lib/faraday/options.rb, line 122 def each_value return to_enum(:each_value) unless block_given? values.each do |value| yield(value) end end
Public
Source
# File lib/faraday/options.rb, line 76 def fetch(key, *args) unless symbolized_key_set.include?(key.to_sym) key_setter = "#{key}=" if !args.empty? send(key_setter, args.first) elsif block_given? send(key_setter, yield(key)) else raise self.class.fetch_error_class, "key not found: #{key.inspect}" end end send(key) end
Public
Source
# File lib/faraday/options.rb, line 148 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
Internal
Source
# File lib/faraday/options.rb, line 115 def key?(key) keys.include?(key) end
Public
Also aliased as: has_key?
Source
# File lib/faraday/options.rb, line 96 def keys members.reject { |member| send(member).nil? } end
Public
Source
# File lib/faraday/options.rb, line 66 def merge(other) dup.merge!(other) end
Public
Source
# File lib/faraday/options.rb, line 51 def merge!(other) other.each do |key, other_value| self_value = send(key) sub_options = self.class.options_for(key) new_value = if self_value && sub_options && other_value self_value.merge(other_value) else other_value end send("#{key}=", new_value) unless new_value.nil? end self end
Public
Source
# File lib/faraday/options.rb, line 198 def symbolized_key_set @symbolized_key_set ||= Set.new(keys.map(&:to_sym)) end
Source
# File lib/faraday/options.rb, line 138 def to_hash hash = {} members.each do |key| value = send(key) hash[key.to_sym] = value unless value.nil? end hash end
Public
Source
# File lib/faraday/options.rb, line 22 def update(obj) obj.each do |key, value| sub_options = self.class.options_for(key) if sub_options new_value = sub_options.from(value) if value elsif value.is_a?(Hash) new_value = value.dup else new_value = value end send("#{key}=", new_value) unless new_value.nil? end self end
Public
Source
# File lib/faraday/options.rb, line 131 def value?(value) values.include?(value) end
Public
Also aliased as: has_value?
Source
# File lib/faraday/options.rb, line 91 def values_at(*keys) keys.map { |key| send(key) } end
Public