lib/hyper_resource.rb in hyperresource-0.2.1 vs lib/hyper_resource.rb in hyperresource-0.2.2
- old
+ new
@@ -42,19 +42,25 @@
## [namespace] Class or class name, into which resources should be
## instantiated.
##
## [headers] Headers to send along with requests for this resource (as
## well as its eventual child resources, if any).
+ ##
+ ## [faraday_options] Configuration passed to +Faraday::Connection.initialize+,
+ ## such as +{request: {timeout: 30}}+.
+ ##
def initialize(opts={})
return init_from_resource(opts) if opts.kind_of?(HyperResource)
self.root = opts[:root] || self.class.root
self.href = opts[:href] || ''
self.auth = (self.class.auth || {}).merge(opts[:auth] || {})
self.namespace = opts[:namespace] || self.class.namespace
self.headers = DEFAULT_HEADERS.merge(self.class.headers || {}).
merge(opts[:headers] || {})
+ self.faraday_options = opts[:faraday_options] ||
+ self.class.faraday_options || {}
## There's a little acrobatics in getting Attributes, Links, and Objects
## into the correct subclass.
if self.class != HyperResource
if self.class::Attributes == HyperResource::Attributes
@@ -133,11 +139,11 @@
self.objects.first[1].each(&block) rescue nil
end
#### Magic
- ## method_missing will load this resource if not yet loaded, then
+ ## method_missing will load this resource if not yet loaded, then
## attempt to delegate to +attributes+, then +objects+, then +links+.
## Override with care.
def method_missing(method, *args)
self.get unless self.loaded
@@ -186,14 +192,15 @@
## Return a new HyperResource based on this object and a given href.
def _hr_new_from_link(href) # @private
- self.class.new(:root => self.root,
- :auth => self.auth,
- :headers => self.headers,
- :namespace => self.namespace,
- :href => href)
+ self.class.new(:root => self.root,
+ :auth => self.auth,
+ :headers => self.headers,
+ :namespace => self.namespace,
+ :faraday_options => self.faraday_options,
+ :href => href)
end
## Returns the class into which the given response should be cast.
## If the object is not loaded yet, or if +namespace+ is