lib/hyper_resource.rb in aptible-resource-1.0.2 vs lib/hyper_resource.rb in aptible-resource-1.1.0.pre.0

- old
+ new

@@ -44,24 +44,19 @@ ## 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 @@ -128,18 +123,18 @@ ## Returns the *i*th object in the first collection of objects embedded ## in this resource. Returns nil on failure. def [](i) get unless loaded - self.objects.first[1][i] rescue nil + self.objects.first[1][i] end ## Iterates over the objects in the first collection of embedded objects ## in this resource. def each(&block) get unless loaded - self.objects.first[1].each(&block) rescue nil + self.objects.first[1].each(&block) end #### Magic ## method_missing will load this resource if not yet loaded, then @@ -197,11 +192,10 @@ def _hr_new_from_link(href) # @private self.class.new(:root => self.root, :auth => self.auth, :headers => self.headers, :namespace => self.namespace, - :faraday_options => self.faraday_options, :token => self.token, :href => href) end @@ -250,10 +244,9 @@ def _hr_response_class # @private self.namespace ||= self.class.to_s unless self.class.to_s=='HyperResource' self.class.response_class(self.response, self.namespace) end - ## Inspects the given Faraday::Response, and returns a string describing ## this resource's data type. ## ## By default, this method looks for a +type=...+ modifier in the