Maddening library loading problem

Hi everyone.
I recently wrote a nice module that I want to use in my rails app. It
consists of a few files in a directory that I have places in the lib
directory. It looks like this:
/lib/KMLTools/foo.rb, bar.rb, baz.rb

Some of these files load each other and I finally got those to work by
using the File.dirname(FILE) trick. When I simply require the file
into my controller, everything is fine, but as soon as i try to create
a new instance of the class i wrote using this code:

d = KMLTools::Document.new()

I get the following error:
NameError in File#save
uninitialized constant KMLTools
This error occured while loading the following files:
kml_tools.rb

Now, there is no file kml_tools.rb, and i am not sure where rails is
getting this file name.
I know i should probably make a gem out of the library i wrote, but I
am not sure if dreamhost lets you install gems.

Does anyone have any suggestions or fixes I could use?
I’ve been trying to figure this out since yesterday and I am really
stymied, any help would be greatly appreciated

Thanks,
Chris

Now, there is no file kml_tools.rb, and i am not sure where rails is
getting this file name.

I’m guessing(!) there’s an implict aasumption somehere that each module
will have a single rb file that loads all the others. Therefore
KMLTools will have a kml_tools.rb which requires all the other bits and
pieces.

As for why rails is trying to load that, I’m not sure…

Alan

On Mar 14, 2006, at 8:10 AM, Alan F. wrote:

As for why rails is trying to load that, I’m not sure…

Alan

The way rails autoloads classes these days is with const_missing.

Which is sort of like method_missing but for constants. So they first
time rails sees KMLTools it looks for a file called kml_tools.rb in
all of the defined load paths.

Cheers-
-Ezra Z.
Yakima Herald-Republic
WebMaster

509-577-7732
[email protected]

Chris,

Did you ever find a solution for this?

I am having the exact same problem but with a RubyGem!!! (see:
RubyGem loading into a controller (High quality question) - Rails - Ruby-Forum)

I will be sure to pass on any info. that I get about my problem.

Thanks,
Wes G.

Ezra Z. wrote:

On Mar 14, 2006, at 8:10 AM, Alan F. wrote:

As for why rails is trying to load that, I’m not sure…

Alan

The way rails autoloads classes these days is with const_missing.
Which is sort of like method_missing but for constants. So they first
time rails sees KMLTools it looks for a file called kml_tools.rb in
all of the defined load paths.

Cheers-
-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
[email protected]

Wes:
Sorry about the delay in response, i did ultimatley get this to work, i
just
created a kml_tools.rb file where the framework was looking for this,
and it
loaded up just fine. I never did figure out WHY this happened.

Lately i hav ebeen having some file capitalization issues going on in my
unit tests, but i think that just might be a mac os x thing.

Chris,

There appears to be a time component to my problem. If I leave my
WEBrick server up for a few minutes, all of a sudden it can find the GEM
and everything works.

Perhaps there is some kind of caching going on with autoloading of
classes???

I don’t know. It’s very strange.

Wes

Wes G. wrote:

Chris,

Did you ever find a solution for this?

I am having the exact same problem but with a RubyGem!!! (see:
RubyGem loading into a controller (High quality question) - Rails - Ruby-Forum)

I will be sure to pass on any info. that I get about my problem.

Thanks,
Wes G.

Ezra Z. wrote:

On Mar 14, 2006, at 8:10 AM, Alan F. wrote:

As for why rails is trying to load that, I’m not sure…

Alan

The way rails autoloads classes these days is with const_missing.
Which is sort of like method_missing but for constants. So they first
time rails sees KMLTools it looks for a file called kml_tools.rb in
all of the defined load paths.

Cheers-
-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
[email protected]