-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
This diff fixes an edge case for scope methods. Previously, when a scope was added to a parent class after both the parent and a child class had been loaded, calling the scope method via the subclass resulted in an exception. With this patch, calling the scope method via the subclass works as expected.
One implementation detail of this patch is that the #scopes method on a Mongoid-mapped class will only return the scopes directly defined on the class itself, not any scopes defined on its parent classes.
Also, since the #scopes attribute is effectively used as an internal implementation detail of the scope methods, it would probably be nice to protect it a little better. As it stands now, the scope descriptor can be overwritten by outside code or the entire data structure can be cleared with scopes.clear, leading every scope method to start throwing exceptions. For what it's worth, ActiveRecord doesn't provide the equivalent of a #scopes method, it just defines the scope methods directly and has no way to enumerate them.