Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8567 (closed defect: incomplete)

Opened 1 year ago

Last modified 1 year ago

[PATCH] Extending of Ares objects doesn't work properly with regard to headers

Reported by: foeken Assigned to: core
Priority: normal Milestone: 1.x
Component: ActiveResource Version: edge
Severity: normal Keywords:
Cc:

Description

When creating a base objects for a remote API i wanted to set the headers on the base object and propagate those to the objects that extend it. Say you want to import all of googles database (not probable ;))

class GoogleObject << ActiveResource::Base
  self.headers["User-Agent"] = "My first program"
  self.site = "http://www.google.com/"
end

Now we want to get the webpages, we define:

class WebPage << GoogleObject
  self.element_name = 'webpages' 
end

Now when you perform WebPage.find(:all) The site is correct, but the headers are empty.

I used the following fix:

def headers
        if defined?(@headers)
          @headers
        elsif superclass != Object and superclass.headers
          superclass.headers
        else
          @headers = {}
        end
      end
      
      
      def headers=(headers)
        @headers = headers
      end

Once again it's quite ugly, but it does work :)

Change History

06/19/07 15:34:49 changed by josh

  • status changed from new to closed.
  • resolution set to incomplete.
  • summary changed from Extending of Ares objects doesn't work properly with regard to headers to [PATCH] Extending of Ares objects doesn't work properly with regard to headers.

Looks like that might do it. Just wrap it up in a diff patch and add some unit tests. If you get that done, I'll clean up the syntax for you.