lib/lazy_resource/resource.rb in lazy_resource-0.3.0 vs lib/lazy_resource/resource.rb in lazy_resource-0.3.2

- old
+ new

@@ -17,10 +17,18 @@ def self.site @site end + def self.default_headers=(headers) + @default_headers = headers + end + + def self.default_headers + @default_headers || {} + end + def self.root_node_name=(node_name) LazyResource::Mapping.root_node_name = node_name end module ClassMethods @@ -33,15 +41,27 @@ LazyResource::Resource.site end end # Sets the URI of the REST resources to map for this class to the value in the +site+ argument. - # The site variable is required for Active Async's mapping to work. + # The site variable is required for LazyResources's mapping to work. def site=(site) @site = site end + def default_headers + if defined?(@default_headers) + @default_headers + else + LazyResource::Resource.default_headers + end + end + + def default_headers=(headers) + @default_headers = headers + end + def from @from end def from=(from) @@ -54,9 +74,11 @@ def find(id, params={}, options={}) self.new(self.primary_key_name => id).tap do |resource| resource.fetched = false resource.persisted = true + options[:headers] ||= {} + options[:headers].reverse_merge!(default_headers) request = Request.new(resource.element_url(params), resource, options) request_queue.queue(request) end end