This project is archived and is in readonly mode.
ActiveModel Naming should take care of anonymous classes
-
gucki
- Tag set to activemodel, rails3.0rc
-
Xavier Noria
- Importance changed from to Low
Don't know about the solution as such, just wanted to comment that AS defines #anonymous? and if the patch is fine it would be preferred over the comparison by hand.
-
gucki
Thanks for the hint with #anonymous?, that's indeed nicer.
The patch against latest master is now available here:
http://github.com/gucki/rails/commit/e0f7490a607f3444223c0769bd5282... -
Xavier Noria
Cool! Yeah in addition to being encapsulated, #name returns either an empty string or nil for anonymous classes/modules, depending on the interpreter.
Rails no longer assumes all Active Support is loaded, you also need to cherry-pick this file active_support/core_ext/module/anonymous.rb:
require 'active_support/core_ext/module/anonymous'to ensure #anonymous is available (it is irrelevant if it is due to previously required code, you know).
-
gucki
Ok, here we go again :-)
http://github.com/gucki/rails/commit/5f58dbb4807cd895a3faa91c484bfb... -
John Firebaugh
Why is lookup_ancestors returning an anonymous class in this case? My guess is the right solution lies in changing that, rather than in explicitly checking anonymous? in #human.
-
gucki
You mean lookup_ancestors should always remove anonymous classes from its result? I guess also anonymous ancestors might be used somewhere and so should be included in the result, but this is to internal to me...sorry.
-
John Firebaugh
If you look at the other places lookup_ancestors is used, none of them expect it to return anonymous classes. I think the !anonymous? check should be in lookup_ancestors, or in a Sequel-specific override of lookup_ancestors.
BTW, this example works for me:
class Message < Sequel::Model include ActiveModel::Validations def text end validates :text, :presence => true, :length => { :within => 1..10000 } end Message.new.valid?I think you must be using something more like:
class Message < Sequel::Model(:message)Which, if you are plugging Sequel's active_model plugin into Sequel::Model, will indeed cause Message.lookup_ancestors to return the anonymous class created by Sequel::Model(:message).
-
gucki
Well, I guess the core team has to decide. So please, could any of the core team members let us know where to patch? I'll then provide the tested patch asap :)
BTW: You might be right, I might have missed the arguments to Sequel::Model in the example above. Sorry :(
-
gucki
So here's the patch to make ActiveModel::Translation#lookup_ancestors ignore anonymous classes. Would be nice if it'd be included in 3.0 final. :)
http://github.com/gucki/rails/commit/5aa7e64eefe388425575204ac7e829... -
Rohit Arondekar
- State changed from new to open
- Assigned user set to Santiago Pastorino
Need more eyes on this ticket and patch. Assigning to Santiago for review.
-
gucki
In the hope it'll soon get fixed upstream :)
def lookup_ancestors self.ancestors.select { |x| x.respond_to?(:model_name) && !x.anonymous? } end -
Jeff Kreeftmeijer
Automatic cleanup of spam.
-
Jeff Kreeftmeijer
Automatic cleanup of spam.
-
Santiago Pastorino
- Milestone cleared.
Is this still an issue? gucki can you provide a patch again? Thanks.