Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Option method access

  • Loading branch information...
commit ac1d9e4f36980bf3d57f0ecb9a54929da60f244e 1 parent 03504db
@technoweenie authored
Showing with 25 additions and 12 deletions.
  1. +25 −12 lib/faraday/options.rb
View
37 lib/faraday/options.rb
@@ -2,28 +2,19 @@ module Faraday
# Subclasses Struct with some special helpers for converting from a Hash to
# a Struct.
class Options < Struct
+ # Public
def self.from(value)
value ? new.update(value) : new
end
- def self.options(mapping)
- attribute_options.update(mapping)
- end
-
- def self.options_for(key)
- attribute_options[key]
- end
-
- def self.attribute_options
- @attribute_options ||= {}
- end
-
+ # Public
def each(&block)
members.each do |key|
block.call key.to_sym, send(key)
end
end
+ # Public
def update(obj)
obj.each do |key, value|
next unless value
@@ -43,29 +34,35 @@ def update(obj)
self
end
+ # Public
def delete(key)
value = send(key)
send("#{key}=", nil)
value
end
+ # Public
def merge(value)
dup.update(value)
end
+ # Public
def fetch(key, default = nil)
send(key) || send("#{key}=", default ||
(block_given? ? Proc.new.call : nil))
end
+ # Public
def values_at(*keys)
keys.map { |key| send(key) }
end
+ # Public
def keys
members.reject { |m| send(m).nil? }
end
+ # Public
def to_hash
hash = {}
members.each do |key|
@@ -75,6 +72,7 @@ def to_hash
hash
end
+ # Internal
def inspect
values = []
members.each do |m|
@@ -85,6 +83,21 @@ def inspect
%(#<#{self.class}#{values}>)
end
+
+ # Internal
+ def self.options(mapping)
+ attribute_options.update(mapping)
+ end
+
+ # Internal
+ def self.options_for(key)
+ attribute_options[key]
+ end
+
+ # Internal
+ def self.attribute_options
+ @attribute_options ||= {}
+ end
end
class RequestOptions < Options.new(:params_encoder, :proxy, :bind,
Please sign in to comment.
Something went wrong with that request. Please try again.