Fully qualifying classes underneath the vendor directory


#1

Can I qualify classes using the first directory name under vendor?

Say I have:

vendor/html-scanner/html/node.rb

Can I qualify the Node class using

HTML-Scanner::HTML::Node?

Thanks,
Wes


#2

Without declaring the namespace using ‘module’?

It might be possible to add a bunch of funky dynamic code that moves
classes into different namespaces according to their location in the
filesystem, but it would be a pain. Just declare the namespace
explicitly.
-tim


#3

Sorry, I wasn’t clear enough.

What I mean is, can I address the class based on the directory
underneath the vendor directory. Assume the class already exists.

Tim B. wrote:

Without declaring the namespace using ‘module’?

It might be possible to add a bunch of funky dynamic code that moves
classes into different namespaces according to their location in the
filesystem, but it would be a pain. Just declare the namespace
explicitly.
-tim


#4

Actually, I’m trying to resolve some mysterious namespace collision and
I’m thinking that if I qualify specifically enough, I’ll be able to get
around it. But that doesn’t appear to be the case.

I have done this:
HTML::Node::Tag.new(parent, line, pos, name, attributes, closing)

but I still can’t successfully instantiate this Tag object. I just
can’t believe that there is another HTML::Node::Tag class floating
around.

There is too much auto-magic-overloading stuff going on and I don’t know
where it’s happening.

Wes

Kirk H. wrote:

On Tuesday 16 May 2006 11:59 am, Wes G. wrote:

Can I qualify classes using the first directory name under vendor?

Say I have:

vendor/html-scanner/html/node.rb

Can I qualify the Node class using

HTML-Scanner::HTML::Node?

There is nothing automatic to make this happen. It needs extra magic
that you
would have to write yourself.

For instance, if node.rb looked something like this:

class Node

Node stuff here…

end

Then you could write your own require-like command:

myrequire ‘vendor/html-scanner/html/node’

That would look at that path, translate it into the desired nested
Module
statements, and then load node.rb into that space.

Is that really what you are needing, though? What are you trying to do?
If
we know that, we may well be able to suggest a simpler approach.

Thanks,

Kirk H.


#5

On Tuesday 16 May 2006 11:59 am, Wes G. wrote:

Can I qualify classes using the first directory name under vendor?

Say I have:

vendor/html-scanner/html/node.rb

Can I qualify the Node class using

HTML-Scanner::HTML::Node?

There is nothing automatic to make this happen. It needs extra magic
that you
would have to write yourself.

For instance, if node.rb looked something like this:

class Node

Node stuff here…

end

Then you could write your own require-like command:

myrequire ‘vendor/html-scanner/html/node’

That would look at that path, translate it into the desired nested
Module
statements, and then load node.rb into that space.

Is that really what you are needing, though? What are you trying to do?
If
we know that, we may well be able to suggest a simpler approach.

Thanks,

Kirk H.