In the example code in this Pastie http://pastie.caboo.se/129000, I''m observing behavior I can''t explain. I''m making two calls to alias_method_chain to extend create_table and drop_table. The create_table alias chain works as expected. While debugging the drop_table_with alias chained method is never entered. Thanks in advance for your help. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Any chance it''s as simple as the placement of your requires? On Apr 2, 12:23 am, Jobu <rosens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In the example code in this Pastiehttp://pastie.caboo.se/129000, I''m > observing behavior I can''t explain. I''m making two calls to > alias_method_chain to extend create_table and drop_table. The > create_table alias chain works as expected. While debugging the > drop_table_with alias chained method is never entered. > > Thanks in advance for your help.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 2, 10:09 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote:> Any chance it''s as simple as the placement of your requires? > > On Apr 2, 12:23 am, Jobu <rosens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > In the example code in this Pastiehttp://pastie.caboo.se/129000, I''m > > observing behavior I can''t explain. I''m making two calls to > > alias_method_chain to extend create_table and drop_table. The > > create_table alias chain works as expected. While debugging the > > drop_table_with alias chained method is never entered. > > > Thanks in advance for your help.I don''t think so. Both create_table_with and drop_table_with are in the same file which is included from environment.rb''s last line ActiveRecord::ConnectionAdapters::SchemaStatements.send(:include, AuditingTables::ActiveRecord::ConnectionAdapters::SchemaStatements) --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Trevor Squires
2008-Apr-03 03:08 UTC
Re: Two alias_method_chain calls: first works second doesn''t
Okay, I haven''t dug deep into this but I can give you a few pointers. First of all, the alias_method_chain is being done to a module so your methods only do stuff when they are actually included in a class. With that in mind, what happens here? module Failure def failure_type "everything is fine" end def failure_type_with_foo puts "I intercepted it!" failure_type_without_foo end alias_method_chain :failure_type, :foo end class SomethingThatFails include Failure def failure_type "epic" end end SomethingThatFails.new.failure_type #=> "epic" This could be an explanation. Regards, Trevor On 4/2/08, Jobu <rosensama-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Apr 2, 10:09 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote: > > Any chance it''s as simple as the placement of your requires? > > > > On Apr 2, 12:23 am, Jobu <rosens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > In the example code in this Pastiehttp://pastie.caboo.se/129000, I''m > > > observing behavior I can''t explain. I''m making two calls to > > > alias_method_chain to extend create_table and drop_table. The > > > create_table alias chain works as expected. While debugging the > > > drop_table_with alias chained method is never entered. > > > > > Thanks in advance for your help. > > I don''t think so. Both create_table_with and drop_table_with are in > the same file which is included from environment.rb''s last line > > ActiveRecord::ConnectionAdapters::SchemaStatements.send(:include, > AuditingTables::ActiveRecord::ConnectionAdapters::SchemaStatements) > > > > > > >-- -- Trevor Squires http://somethinglearned.com --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry I should have been more specific. Your pastie shows: line 13: def drop_table_with_auditing_table line 20 require ''rails_generator'' line 21 require ''rails_generator/scripts/generate'' line 23 def create_table_with_auditing_table Since the code that works follows the requires at lines 20 and 21 I thought they might provide something helpful. On a side note, depending on what your audit code needs to accomplish "acts_as_versioned" might be a good fit. On Apr 2, 10:34 pm, Jobu <rosens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 2, 10:09 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote: > > > Any chance it''s as simple as the placement of your requires? > > > On Apr 2, 12:23 am, Jobu <rosens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > In the example code in this Pastiehttp://pastie.caboo.se/129000, I''m > > > observing behavior I can''t explain. I''m making two calls to > > > alias_method_chain to extend create_table and drop_table. The > > > create_table alias chain works as expected. While debugging the > > > drop_table_with alias chained method is never entered. > > > > Thanks in advance for your help. > > I don''t think so. Both create_table_with and drop_table_with are in > the same file which is included from environment.rb''s last line > > ActiveRecord::ConnectionAdapters::SchemaStatements.send(:include, > AuditingTables::ActiveRecord::ConnectionAdapters::SchemaStatements)--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 3, 10:14 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote:> Sorry I should have been more specific. Your pastie shows: > > line 13: def drop_table_with_auditing_table > > line 20 require ''rails_generator'' > line 21 require ''rails_generator/scripts/generate'' > > line 23 def create_table_with_auditing_table > > Since the code that works follows the requires at lines 20 and 21 I > thought they might provide something helpful.drop_table_with_auditing_table doesn''t require the code in the requires. Also, that function''s not even being entered.> > On a side note, depending on what your audit code needs to accomplish > "acts_as_versioned" might be a good fit. > > On Apr 2, 10:34 pm, Jobu <rosens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Apr 2, 10:09 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote: > > > > Any chance it''s as simple as the placement of your requires? > > > > On Apr 2, 12:23 am, Jobu <rosens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > In the example code in this Pastiehttp://pastie.caboo.se/129000, I''m > > > > observing behavior I can''t explain. I''m making two calls to > > > > alias_method_chain to extend create_table and drop_table. The > > > > create_table alias chain works as expected. While debugging the > > > > drop_table_with alias chained method is never entered. > > > > > Thanks in advance for your help. > > > I don''t think so. Both create_table_with and drop_table_with are in > > the same file which is included from environment.rb''s last line > > > ActiveRecord::ConnectionAdapters::SchemaStatements.send(:include, > > AuditingTables::ActiveRecord::ConnectionAdapters::SchemaStatements)--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for looking, but I believe I''ve tried what you suggest. 1) I believe the extension to the module is included in the extended module globally, because of the following line in environment.rb ActiveRecord::ConnectionAdapters::SchemaStatements.send(:include,AuditingTables::ActiveRecord::ConnectionAdapters::SchemaStatements) 2) I''ve used a debugger and seen that the failure_type_with_foo (my drop_table_with_auditing_table) in your example is never entered. However my create_table_with_auditing_table, which is defined and included in an identical manner is always entered. Could something be overriding or blocking my extension of drop_table? On Apr 2, 11:08 pm, "Trevor Squires" <tre...-k8q5a0yEZAgS+FvcfC7Uqw@public.gmane.org> wrote:> Okay, > > I haven''t dug deep into this but I can give you a few pointers. > > First of all, the alias_method_chain is being done to a module so your > methods only do stuff when they are actually included in a class. > > With that in mind, what happens here? > > module Failure > def failure_type > "everything is fine" > end > > def failure_type_with_foo > puts "I intercepted it!" > failure_type_without_foo > end > alias_method_chain :failure_type, :foo > end > > class SomethingThatFails > include Failure > def failure_type > "epic" > end > end > > SomethingThatFails.new.failure_type #=> "epic" > > This could be an explanation. > > Regards, > Trevor > > On 4/2/08, Jobu <rosens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > On Apr 2, 10:09 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote: > > > Any chance it''s as simple as the placement of your requires? > > > > On Apr 2, 12:23 am, Jobu <rosens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > In the example code in this Pastiehttp://pastie.caboo.se/129000, I''m > > > > observing behavior I can''t explain. I''m making two calls to > > > > alias_method_chain to extend create_table and drop_table. The > > > > create_table alias chain works as expected. While debugging the > > > > drop_table_with alias chained method is never entered. > > > > > Thanks in advance for your help. > > > I don''t think so. Both create_table_with and drop_table_with are in > > the same file which is included from environment.rb''s last line > > > ActiveRecord::ConnectionAdapters::SchemaStatements.send(:include, > > AuditingTables::ActiveRecord::ConnectionAdapters::SchemaStatements) > > -- > -- > Trevor Squireshttp://somethinglearned.com--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Trevor Squires
2008-Apr-07 15:13 UTC
Re: Two alias_method_chain calls: first works second doesn''t
On 4/6/08, Jobu <rosensama-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 2) I''ve used a debugger and seen that the failure_type_with_foo (my > drop_table_with_auditing_table) in your example is never entered. > However my create_table_with_auditing_table, which is defined and > included in an identical manner is always entered. > > Could something be overriding or blocking my extension of drop_table?Yeah, that''s the whole point of what I showed you. No amount of monkeypatching in the Failure module can compensate for the fact that the SomethingThatFails class defines its own failure_type() method. Try to figure out the type of the object you are calling drop_table() on, then look at the rails source to see whether that class in question happens to define its own drop_table method. If you''re impatient you can always just search for "def drop_table" in the rails source. Chances are, you''re going to have to monkeypatch that class rather than SchemaStatements. HTH Trevor -- -- Trevor Squires http://somethinglearned.com --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---