Skip to content

Instantly share code, notes, and snippets.

@troex
Created November 29, 2011 10:12
Show Gist options
  • Save troex/1404284 to your computer and use it in GitHub Desktop.
Save troex/1404284 to your computer and use it in GitHub Desktop.
Hack ActiveResource::Base to support per instance site option
class Runner
@@nodes = {}
def self.node(site)
@@nodes[site] || = self.new_ar(site).new if !@@nodes.has_key?(site)
end
def self.new_ar(site)
Class.new(ActiveResource::Base) do
self.site = site
self.element_name = 'runner'
# your methods here
end
end
end
@troex
Copy link
Author

troex commented Jan 29, 2012

Usage:

remote = Runner.node('http://localhost')
remote.get(...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment