monkey-patching const_missing and friends

J

John Lam

In RubyCLR, I currently have a baseline dependency on ActiveRecord
because I need to patch const_missing *after* ActiveRecord does.So in
my top rubyclr.rb file it looks something like:

require 'rubygems'
require_gem 'ActiveRecord'

... lots of other requires for RubyCLR stuff.

require 'databinding'


Now, RubyCLR core doesn't have a dependency on databinding, only the
databinding 'extensions' do. I'd only like to drag in the dependency
on ActiveRecord when a user needs the databinding extensions, so I'd
like their program to look like:

require 'rubyclr'
require 'databinding'

to explicitly state their intent.

However, if I require ActiveRecord in the databinding module, it wipes
out my monkey patching of const_missing and friends (they're not
delegating properly, at least on the 1.3.1 local build that I have on
my dev box). The offending line of code is in dependencies.rb:123:

raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e)

They instead should be delegating to rails_original_const_missing instead.

Now, this isn't really the issue here - I'll report this bug through
the normal channels. Instead, it raises the larger issue of how to
co-exist with other libraries who might be doing 'bad' things like
this.

I *think* I'd like to re-run my core.rb file that monkey patches
everything after the offending library. My questions are:

1) Is this a good idea at all? (workarounds would be appreciated :)
2) How would I re-run my core.rb file? Would I read it in and then eval it?

Thanks
-John
http://www.iunknown.com
(Contact me off-list via (e-mail address removed))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top