It feels like, by providing a way around this, we're sort of voiding the
whole purpose of it in the first place.
But then again, I've been out of the loop as of late, so it's possible I'm
just missing something.
..nap
..nap
I wondered about that too. I would recommend that once we figure out
the issue of controlling mass-assignment access we look hard at the
Resource#private_attributes and Resource#private_attributes= methods,
and remove them if at all possible. It is marked as private now,
which is a good first step, but it would be alot nicer to have
everything sent through attributes= for simplicity's sake.
On a related note, anyone think the way Resource#attributes= isimplemented is just asking for trouble? Note how we take the key that
was passed-in (potentially from a web form), append an "=", and then
pass it to send() directly? That seems like it could be pretty
dangerous. Probably better to only process the hash entries that
match the names of properties defined within the model.
Still, there isn't much of a use case for a protected setters vs private
setts differentiation from DM's point of view. At least, not as far as I
can tell.
..nap
Still, there isn't much of a use case for a protected setters vs private
setts differentiation from DM's point of view. At least, not as far as I
can tell.
..nap
I see the reasoning for wanting something akin to AR's attr_accessible
here (for mass assignment reasons, almost like two different levels of
"protection" and we're getting our terminology confused). Although I still
sort of feel that those mass-assignment rules are kind of an ugly hack,
being able to do that and include/exclude attributes is none the less
convenient and I can't think of a better strategy.
Perhaps the terminology is the biggest issue of all, since my message
before got confused :). Maybe that translates to a vote that :protected
shouldn't be overridden after all. Maybe :accessible => true (default to
false) isn't a bad way to go.
Hope that's clear :).
..nap
# def set_attributes(input, allowed_methods = nil)
# raise ArgumentError.new("+input+ should be a Hash but was
#{input.inspect}") unless Hash === input
# if allowed_methods
# input.each_pair do |k,v|
# send(k, v) if allowed_methods.include?(k)
# end
# else
# if input.tainted?
# set_attributes(input, properties.public_method_names)
# else
# input.each_pair do |k,v|
# send(k, v)
# end
# end
# end
There is another option which I like a lot which is a class method which calls down into "set_attributes" with the more liberal list of properties that can be updated. The advantage of something at the class method level is that it could be turned off or on based upon the developer choice at time of creation. So it's possible that TableA would allow overrides of the protection and TableB would be on complete lockdown and not allow standard calls to override the protection scheme as placed on the model (Ruby never allows one to completely say never :) ). This wouldn't add any overhead because it can be done with a single call at time of creation of the class. I personally prefer this option the best of anything at the moment. It gives me my security guard and I can arm him rather heavily if I so desire :)