Hi there,
I've been using Active Resource pretty heavily over the last four months and have found, like many, that it's not as much like Active Record as I'd really like. So I've been improving a plugin called Hyperactive Resource which does just that. (http://github.com/ taryneast/hyperactiveresource/tree/master)
I've got it to a state where it's fairly useful, and want to start moving some of my stuff back into Active Resource itself. I spoke with Yehuda at Rails Underground and he said that this would be useful - especially the validations and callbacks.
My fork of rails is here:
I've got a lot of stuff I'd like to do to pull in my work from Hyres. Some of it may change the way that Active Resource behaves and I'd like to chat to you guys about whether it's a) wanted b) the best way to go about it.
As an example to begin with. I added Validations by using the ActiveModel::Validations module (BTB - is that a module or a component?)
I also added ,as yehuda called it, a couple of simple smoke-tests to make sure they work. They do - but with a caveat: validates_presence_of expects that an attribute will return 'nil' if it's not set... and doesn't recognise a MethodMissing as meaning "this attribute is not set yet".
ARes, as it currently stands, does not provide a MethodMissing for attributes unless they are present on the object because we currently don't know what "column-equivalents" we're likely to get back from the remote system.
That's fine for somebody grabbing remote objects from a system where they don't know the structure of the objects they're getting back... but in my experience so far - that's reasonably rare. Most of the systems that access a remote API (at least that I've worked on) run against a known API with known attributes... IMHO there should be no reason why we couldn't provide a set of known attributes/"columns" for ARes to do something useful with.
This is how HyRes works. You can manually hand it a set of columns that can then be used to feed MethodMissing and nicely spit out a nil if the attribute is not currently set on the given object.
We *could* override validates_presence_of to not explode with an Exception in this case - but that feels ugly to me... and somehow a little dangerous. IMO the HyRes method makes more sense. The known columns do not interfere with any pre-existing functionality which allows any values that come back from the remote system to be set as attributes - which means we just get an added benefit without any disruption to existing code.
This helps us with the validates_presence_of situation, because if we're running validations on it - it'll be on a column that we know about. But it also paves the way for a whole bunch of other functionality as well (eg attr_accessible/protected and some funky stuff once you start getting into Associations - but more on that later).
So my question is - are columns ok? and is anybody interested? If so - how do I go about getting this stuff back into Rails?
Cheers, Taryn