This project is archived and is in readonly mode.
ActiveResource should support URI::Generic
-
Ian Smith-Heisters
I'll try that as an attachment
-
Gaius Centus Novus
Seems fine; in fact, seems like the "truer" test of what's intended, but I can't see setting the connection URL to anything other than HTTP or HTTPS.
Maybe the use case is using ActiveResource to find things on the same server? In that case, you might pass a root-relative instead of absolute string to URI::parse (like '/my-other-app/'), which would return a URI::Generic. In that case, though, SSL (a) would be unnecessary and (b) still couldn't be determined from the URI.
-
Ian Smith-Heisters
My use case was allowing configuration with a YAML file like so:
# See URI::Generic#build for possible configuration options scheme: http host: 127.0.0.1 userinfo: 'username:password' port: 3000 path: /Then you read it into ActiveResource like so:
CONFIG = YAML.load(ERB.new(File.read(File.join(RAILS_ROOT, 'config', 'intranet.yml'))).result).with_indifferent_access self.site = URI::Generic.build(CONFIG)Generic is necessary because developers will be using http on localhost, while production servers will use https.
HTH
-
Gaius Centus Novus
Why not do this:
in conf/intranet.yml:
active_resource_url: http://user:password@127.0.0.1:3000/path
in loader.rb:
CONFIG = YAML.load(ERB.new(File.read(File.join(RAILS_ROOT, 'config',
'intranet.yml'))).result).with_indifferent_access
self.site = URI::parse(CONFIG[:active_resource_url)
That way, the developers can specify whatever they want, and you
always get an HTTP or HTTPS URI.
-James
-
Ian Smith-Heisters
yeah, that's essentially what I'm doing now, except that I approached it by modifying
self.site = URI::Generic.build(CONFIG)to
self.site = URI::Generic.build(CONFIG).to_s...exploiting the fact that self.site= will call URI.parse for me. IMO it's just a little nicer in that it still allows specifying the url in its various parts with labels (clearer), and that it keeps CONFIG namespaced to the ActiveResource descendant. Six of one, half a dozen of the other.
The point isn't that there isn't a workaround, but that the duck typing approach is just slightly more flexible and less surprising.
-
Gaius Centus Novus
No, I like your fix. My point was that the fix is really for the sake of "doing the right thing" rather than providing some unavailable functionality.
-
Ian Smith-Heisters
absolutely 100% agreed ;)
-
Pratik
- State changed from invalid to incomplete
-
Rohit Arondekar
- State changed from incomplete to stale
- Importance changed from to
Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.