What''s the accepted best way to run Edge Rails with local modifications to the source files? I had to modify mysql_adapter.rb to support utf-8 (see previous post: UTF-8?), however I would rather not have to do this modification for every new project I create. Not to mention having to redo the mod every time I update the externals. Any ideas? Thanks, ___________________ Ben Jackson Diretor de Desenvolvimento ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org http://www.incomumdesign.com
On 6/2/05, Ben Jackson <ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> What''s the accepted best way to run Edge Rails with local modifications > to the source files? I had to modify mysql_adapter.rb to support utf-8 > (see previous post: UTF-8?), however I would rather not have to do this > modification for every new project I create. Not to mention having to > redo the mod every time I update the externals. Any ideas? Thanks,I keep mine in a central directory that''s symlinked for all the applications. However, if you''re on windows, keep a diff patch handy so you can export and apply the patch easily. I''m not sure if Windows supports symbolic links at all. -- rick http://techno-weenie.net
On Jun 2, 2005, at 8:37 AM, Ben Jackson wrote:> What''s the accepted best way to run Edge Rails with local > modifications to the source files? I had to modify mysql_adapter.rb > to support utf-8 (see previous post: UTF-8?), however I would > rather not have to do this modification for every new project I > create. Not to mention having to redo the mod every time I update > the externals. Any ideas? Thanks,Thanks to the power of Ruby''s open classes you rarely need to make modifications to the original source. Just open the class and redefine the methods you''d like. For example, toss an extension in lib/mysql_adapter_ext.rb: class ActiveRecord::ConnectionAdapters::MysqlAdapter alias_method :old_some_method, :some_method def some_method # .. do stuff .. then call old method old_some_method end end Then require it in config/environment.rb after the Rails requires and before the database connection. If your override is generally useful, consider submitting it as an enhancement request. Best, jeremy
Here''s my extension: class ActiveRecord::Base alias_method :mysql_connection, :mysql_connection_ext def mysql_connection_ext mysql_connection conn = Mysql::real_connect(host, username, password, database, port, socket) conn.query("SET NAMES ''utf8'';") ConnectionAdapters::MysqlAdapter.new(conn, logger) end end I''m getting the following error upon starting webrick: in `alias_method'': undefined method `mysql_connection_ext'' for class `ActiveRecord::Base'' (NameError) - Ben On 2 Jun 2005, at 14:06, Jeremy Kemper wrote:> On Jun 2, 2005, at 8:37 AM, Ben Jackson wrote: >> What''s the accepted best way to run Edge Rails with local >> modifications to the source files? I had to modify mysql_adapter.rb >> to support utf-8 (see previous post: UTF-8?), however I would rather >> not have to do this modification for every new project I create. Not >> to mention having to redo the mod every time I update the externals. >> Any ideas? Thanks, > > Thanks to the power of Ruby''s open classes you rarely need to make > modifications to the original source. Just open the class and > redefine the methods you''d like. > > For example, toss an extension in lib/mysql_adapter_ext.rb: > > class ActiveRecord::ConnectionAdapters::MysqlAdapter > alias_method :old_some_method, :some_method > > def some_method > # .. do stuff .. then call old method > old_some_method > end > end > > Then require it in config/environment.rb after the Rails requires and > before the database connection. > > If your override is generally useful, consider submitting it as an > enhancement request. > > Best, > jeremy > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Hello, On 6/2/05, Ben Jackson <ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> > Here''s my extension: > > class ActiveRecord::Base > alias_method :mysql_connection, :mysql_connection_ext > > def mysql_connection_ext > mysql_connection > conn = Mysql::real_connect(host, username, password, database, port, > socket) > conn.query("SET NAMES ''utf8'';") > ConnectionAdapters::MysqlAdapter.new(conn, logger) > end > end >I think it should be like: alias_method :mysql_connection_old, :mysql_connection def mysql_connection mysql_connection_old -- Rafael Rezende _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> Here''s my extension: > > class ActiveRecord::Base > alias_method :mysql_connection, :mysql_connection_ext > > def mysql_connection_ext> I''m getting the following error upon starting webrick: > in `alias_method'': undefined method `mysql_connection_ext'' for class > `ActiveRecord::Base'' (NameError)I think that''s because mysql_connection is a class method. Try this: def self.mysql_connection_ext -- rick http://techno-weenie.net
On 6/2/05, Rick Olson <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 6/2/05, Ben Jackson <ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: > > What''s the accepted best way to run Edge Rails with local modifications > > to the source files? I had to modify mysql_adapter.rb to support utf-8 > > (see previous post: UTF-8?), however I would rather not have to do this > > modification for every new project I create. Not to mention having to > > redo the mod every time I update the externals. Any ideas? Thanks, > > I keep mine in a central directory that''s symlinked for all the > applications. However, if you''re on windows, keep a diff patch handy > so you can export and apply the patch easily. I''m not sure if Windows > supports symbolic links at all.It''s a little known fact by XP does support links: http://shell-shocked.org/article.php?id=284 -- sam http://www.magpiebrain.com/
> It''s a little known fact by XP does support links: > > http://shell-shocked.org/article.php?id=284Not Windows XP, NTFS. If you''re using Windows XP (or 2000) on FAT32 then it won''t work. -- Phillip Hutchings http://www.sitharus.com/ sitharus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org / sitharus-QrR4M9swfipWk0Htik3J/w@public.gmane.org
Windows doesn''t have symlinks, but you can use a junction to get the same result: http://www.sysinternals.com/ntw2k/source/misc.shtml#junction Rick Olson wrote: On 6/2/05, Ben Jackson wrote: What''s the accepted best way to run Edge Rails with local modifications to the source files? I had to modify mysql_adapter.rb to support utf-8 (see previous post: UTF-8?), however I would rather not have to do this modification for every new project I create. Not to mention having to redo the mod every time I update the externals. Any ideas? Thanks, I keep mine in a central directory that''s symlinked for all the applications. However, if you''re on windows, keep a diff patch handy so you can export and apply the patch easily. I''m not sure if Windows supports symbolic links at all. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Ben Jackson
2005-Jun-07 20:02 UTC
Re: Running Edge Rails with local modifications [was: UTF-8?]
Ok. Tried that and am getting a new error: class ActiveRecord::Base def self.mysql_connection_ext(config) self.mysql_connection(config) conn = Mysql::real_connect(host, username, password, database, port, socket) conn.query("SET NAMES ''utf8'';") ConnectionAdapters::MysqlAdapter.new(conn, logger) end alias_method :mysql_connection, self.mysql_connection_ext end ./lib/mysql_adaptor_ext.rb:11:in `mysql_connection_ext'': wrong number of arguments (0 for 1) (ArgumentError) - Ben On Jun 2, 2005, at 5:37 PM, Rick Olson wrote:>> Here''s my extension: >> >> class ActiveRecord::Base >> alias_method :mysql_connection, :mysql_connection_ext >> >> def mysql_connection_ext > >> I''m getting the following error upon starting webrick: >> in `alias_method'': undefined method `mysql_connection_ext'' for class >> `ActiveRecord::Base'' (NameError) > > I think that''s because mysql_connection is a class method. Try this: > > def self.mysql_connection_ext > > > -- > rick > http://techno-weenie.net > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
John Higgins
2005-Jun-07 20:41 UTC
Re: Running Edge Rails with local modifications [was: UTF-8?]
Might I suggest another option for you. I''m not a fan of the current solution you are trying because it opens up 2 connections to the database and 2 connection adapters as well. How about this.... module ActiveRecord module ConnectionAdapters class MysqlAdapter def set_names(name) -y1ricOmiHYbs0idC0E/eQA@public.gmane.org("SET NAMES ''#{name}'';") end end class Base alias_method self.mysql_connection_pre_names self.mysql_connection def self.mysql_connection(config) adapter = self.mysql_connection_pre_names(config) adapter.set_names("utf8") end end end First we add a method to mysql_adapter to run the SET NAMES query for us with the appropriate parameter. Instead of trying to modify the original mysql_connection - we first alias it (so that it can be called again once we override it with our new version). Then we call the old version and then using the returned adapter call our new function with utf8 as our parameter. I''m at work so I don''t have a running system to make sure this will work but a quick cut and paste on your side should see if I''m even in the ballpark...... -- John W Higgins wishdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
John Higgins
2005-Jun-07 20:46 UTC
Re: Running Edge Rails with local modifications [was: UTF-8?]
Sorry the brain is a little slow today - this is better (note the change in set_names from @connection.query to execute - I forgot I was inside the adapter at this point) module ActiveRecord module ConnectionAdapters class MysqlAdapter def set_names(name) execute("SET NAMES ''#{name}'';") end end class Base alias_method self.mysql_connection_pre_names self.mysql_connection def self.mysql_connection(config) adapter = self.mysql_connection_pre_names(config) adapter.set_names("utf8") end end end -- John W Higgins wishdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Ben Jackson
2005-Jun-07 20:49 UTC
Re: Running Edge Rails with local modifications [was: UTF-8?]
I got the following errors (after correcting parse error on line 7): ./lib/mysql_adaptor_ext.rb:11: warning: parenthesize argument(s) for future version ./lib/mysql_adaptor_ext.rb:11:in `mysql_connection'': wrong number of arguments (0 for 1) (ArgumentError) I think this has something to do with the arguments that alias_method accepts: it looks for a symbol or a string. Substituting the line alias_method "self.mysql_connection_pre_names", "self.mysql_connection" Gives this error: ./lib/mysql_adaptor_ext.rb:11:in `alias_method'': undefined method `self.mysql_connection'' for class `ActiveRecord::Base'' (NameError) On Jun 7, 2005, at 5:41 PM, John Higgins wrote:> Might I suggest another option for you. I''m not a fan of the current > solution you are trying because it opens up 2 connections to the > database and 2 connection adapters as well. > > How about this.... > > module ActiveRecord > module ConnectionAdapters > class MysqlAdapter > def set_names(name) > @connection.query("SET NAMES ''#{name}'';") > end > end > > class Base > alias_method self.mysql_connection_pre_names self.mysql_connection > > def self.mysql_connection(config) > adapter = self.mysql_connection_pre_names(config) > adapter.set_names("utf8") > end > end > end > > First we add a method to mysql_adapter to run the SET NAMES query for > us with the appropriate parameter. > Instead of trying to modify the original mysql_connection - we first > alias it (so that it can be called again once we override it with our > new version). Then we call the old version and then using the returned > adapter call our new function with utf8 as our parameter. > > I''m at work so I don''t have a running system to make sure this will > work but a quick cut and paste on your side should see if I''m even in > the ballpark...... > > -- > John W Higgins > wishdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Michael Koziarski
2005-Jun-07 20:58 UTC
Re: Running Edge Rails with local modifications [was: UTF-8?]
On 6/8/05, Ben Jackson <ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> I got the following errors (after correcting parse error on line 7): > > ./lib/mysql_adaptor_ext.rb:11: warning: parenthesize argument(s) for > future version > ./lib/mysql_adaptor_ext.rb:11:in `mysql_connection'': wrong number of > arguments (0 for 1) (ArgumentError) > > I think this has something to do with the arguments that alias_method > accepts: it looks for a symbol or a string. Substituting the line > > alias_method "self.mysql_connection_pre_names", "self.mysql_connection"It''s a little more tricky to alias class methods (static in javaspeak). Have a look at what I did, with david''s help, in the locking code. http://dev.rubyonrails.org/file/trunk/activerecord/lib/active_record/locking.rb> Gives this error: > ./lib/mysql_adaptor_ext.rb:11:in `alias_method'': undefined method > `self.mysql_connection'' for class `ActiveRecord::Base'' (NameError) > > On Jun 7, 2005, at 5:41 PM, John Higgins wrote: > > > Might I suggest another option for you. I''m not a fan of the current > > solution you are trying because it opens up 2 connections to the > > database and 2 connection adapters as well. > > > > How about this.... > > > > module ActiveRecord > > module ConnectionAdapters > > class MysqlAdapter > > def set_names(name) > > @connection.query("SET NAMES ''#{name}'';") > > end > > end > > > > class Base > > alias_method self.mysql_connection_pre_names self.mysql_connection > > > > def self.mysql_connection(config) > > adapter = self.mysql_connection_pre_names(config) > > adapter.set_names("utf8") > > end > > end > > end > > > > First we add a method to mysql_adapter to run the SET NAMES query for > > us with the appropriate parameter. > > Instead of trying to modify the original mysql_connection - we first > > alias it (so that it can be called again once we override it with our > > new version). Then we call the old version and then using the returned > > adapter call our new function with utf8 as our parameter. > > > > I''m at work so I don''t have a running system to make sure this will > > work but a quick cut and paste on your side should see if I''m even in > > the ballpark...... > > > > -- > > John W Higgins > > wishdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz
Ben Jackson
2005-Jun-07 21:11 UTC
Re: Running Edge Rails with local modifications [was: UTF-8?]
I looked at the locking code and tried this out: module ActiveRecord def self.append_features(base) super base.class_eval do alias_method :mysql_connection, :mysql_connection_ext end end def mysql_connection_ext(config) adapter = self.mysql_connection(config) adapter.set_names("utf8") end module ConnectionAdapters class MysqlAdapter def set_names(name) execute("SET NAMES ''#{name}'';") end end end end It compiles fine, but the method isn''t getting overridden. - Ben On Jun 7, 2005, at 5:58 PM, Michael Koziarski wrote:> On 6/8/05, Ben Jackson <ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: >> I got the following errors (after correcting parse error on line 7): >> >> ./lib/mysql_adaptor_ext.rb:11: warning: parenthesize argument(s) for >> future version >> ./lib/mysql_adaptor_ext.rb:11:in `mysql_connection'': wrong number of >> arguments (0 for 1) (ArgumentError) >> >> I think this has something to do with the arguments that alias_method >> accepts: it looks for a symbol or a string. Substituting the line >> >> alias_method "self.mysql_connection_pre_names", >> "self.mysql_connection" > > It''s a little more tricky to alias class methods (static in > javaspeak). Have a look at what I did, with david''s help, in the > locking code. > > http://dev.rubyonrails.org/file/trunk/activerecord/lib/active_record/ > locking.rb > >> Gives this error: >> ./lib/mysql_adaptor_ext.rb:11:in `alias_method'': undefined method >> `self.mysql_connection'' for class `ActiveRecord::Base'' (NameError) >> >> On Jun 7, 2005, at 5:41 PM, John Higgins wrote: >> >>> Might I suggest another option for you. I''m not a fan of the current >>> solution you are trying because it opens up 2 connections to the >>> database and 2 connection adapters as well. >>> >>> How about this.... >>> >>> module ActiveRecord >>> module ConnectionAdapters >>> class MysqlAdapter >>> def set_names(name) >>> @connection.query("SET NAMES >>> ''#{name}'';") >>> end >>> end >>> >>> class Base >>> alias_method self.mysql_connection_pre_names >>> self.mysql_connection >>> >>> def self.mysql_connection(config) >>> adapter = >>> self.mysql_connection_pre_names(config) >>> adapter.set_names("utf8") >>> end >>> end >>> end >>> >>> First we add a method to mysql_adapter to run the SET NAMES query for >>> us with the appropriate parameter. >>> Instead of trying to modify the original mysql_connection - we first >>> alias it (so that it can be called again once we override it with our >>> new version). Then we call the old version and then using the >>> returned >>> adapter call our new function with utf8 as our parameter. >>> >>> I''m at work so I don''t have a running system to make sure this will >>> work but a quick cut and paste on your side should see if I''m even in >>> the ballpark...... >>> >>> -- >>> John W Higgins >>> wishdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >>> _______________________________________________ >>> Rails mailing list >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > -- > Cheers > > Koz > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Just wanted to briefly revive this thread. Has anyone else come up with a solution to this problem? - Ben On Jun 7, 2005, at 6:11 PM, Ben Jackson wrote:> I looked at the locking code and tried this out: > > module ActiveRecord > def self.append_features(base) > super > base.class_eval do > alias_method :mysql_connection, :mysql_connection_ext > end > end > > def mysql_connection_ext(config) > adapter = self.mysql_connection(config) > adapter.set_names("utf8") > end > > module ConnectionAdapters > class MysqlAdapter > def set_names(name) > execute("SET NAMES ''#{name}'';") > end > end > end > end > > It compiles fine, but the method isn''t getting overridden. > > - Ben > > On Jun 7, 2005, at 5:58 PM, Michael Koziarski wrote: >> >> It''s a little more tricky to alias class methods (static in >> javaspeak). Have a look at what I did, with david''s help, in the >> locking code. >> >> http://dev.rubyonrails.org/file/trunk/activerecord/lib/active_record/ >> locking.rb >> >>> >>>> Might I suggest another option for you. I''m not a fan of the current >>>> solution you are trying because it opens up 2 connections to the >>>> database and 2 connection adapters as well. >>>> >>>> How about this.... >>>> >>>> module ActiveRecord >>>> module ConnectionAdapters >>>> class MysqlAdapter >>>> def set_names(name) >>>> @connection.query("SET NAMES >>>> ''#{name}'';") >>>> end >>>> end >>>> >>>> class Base >>>> alias_method self.mysql_connection_pre_names >>>> self.mysql_connection >>>> >>>> def self.mysql_connection(config) >>>> adapter = >>>> self.mysql_connection_pre_names(config) >>>> adapter.set_names("utf8") >>>> end >>>> end >>>> end >>>> >>>> First we add a method to mysql_adapter to run the SET NAMES query >>>> for >>>> us with the appropriate parameter. >>>> Instead of trying to modify the original mysql_connection - we first >>>> alias it (so that it can be called again once we override it with >>>> our >>>> new version). Then we call the old version and then using the >>>> returned >>>> adapter call our new function with utf8 as our parameter. >>>> >>>> I''m at work so I don''t have a running system to make sure this will >>>> work but a quick cut and paste on your side should see if I''m even >>>> in >>>> the ballpark...... >>>> >>>> -- >>>> John W Higgins >>>> wishdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >>>> _______________________________________________ >>>> Rails mailing list >>>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>> http://lists.rubyonrails.org/mailman/listinfo/rails >>>> >>> >>> _______________________________________________ >>> Rails mailing list >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >
How about this - I''ll write up a patch for the mysql adapter over the weekend and submit the ticket and as well I''ll send you a copy that you can apply to your system right now. We''ll add charset to the list of available config options so that you can just add it in with hostname and such. The adapter will make the call to SET NAMES if charset is in the config options. David''s pretty good about accepting patches that make sense and I think this isn''t an unreasonable config option to allow - which means there shouldn''t be a problem with it not getting into the code base. I can see how people using mysql would need this in many cases. In fact maybe a more general patch might be in order for the future to cover more adapters. John W Higgins wishdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org