Arne-Kolja Bachstein
2010-Jan-14 13:02 UTC
Modules/Mixins and accessing the calling object?
Hello there, I am stuck at a problem regarding modules here. I have a module that''s included in my model and I need to get to know the class name of my model from within the module. Problem is, that "self" is always pointing to the module class (at least I think so) and I do not know how to access the calling object. Here''s the code: module ActiveRecord module Acts module AclControlled def self.included(base) base.send :extend, InstanceMethods base.send :extend, ClassMethods end module InstanceMethods def controlled_object Rails.logger.info "Fetching ControlledObject..." controlled_object = ControlledObject.find (:first, :conditions => {:model => self.class.to_s, :model_id => self.id }) end end [...] end end end ActiveRecord::Base.send :include, ActiveRecord::Acts::AclControlled Does anyone know how to get access to the calling object here? I tried the super object too, but this seems to point to the model without the mixin somehow. Thanks in advance Arne -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Arne-Kolja Bachstein
2010-Jan-15 10:01 UTC
Re: Modules/Mixins and accessing the calling object?
Have to close this one, as it was my fault. Didn''t notice that some of the methods I want to call are bound to classes rather than objects and of course I tested with the wrong ones. Sorry guys, but thanks again for your attention :-) Cheers Arne On 14 Jan., 14:02, Arne-Kolja Bachstein <arnekolja.bachst...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hello there, > > I am stuck at a problem regarding modules here. I have a module that''s > included in my model and I need to get to know the class name of my > model from within the module. Problem is, that "self" is always > pointing to the module class (at least I think so) and I do not know > how to access the calling object. > > Here''s the code: > > module ActiveRecord > module Acts > module AclControlled > def self.included(base) > base.send :extend, InstanceMethods > base.send :extend, ClassMethods > end > > module InstanceMethods > def controlled_object > Rails.logger.info "Fetching ControlledObject..." > controlled_object = ControlledObject.find > (:first, :conditions => {:model => self.class.to_s, :model_id => > self.id }) > end > end > > [...] > end > end > end > ActiveRecord::Base.send :include, ActiveRecord::Acts::AclControlled > > Does anyone know how to get access to the calling object here? I tried > the super object too, but this seems to point to the model without the > mixin somehow. > > Thanks in advance > > Arne-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.