Forum: Ruby Fully qualifying classes underneath the vendor directory

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Wes G. (Guest)
on 2006-05-16 21:59
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
Tim B. (Guest)
on 2006-05-16 22:10
(Received via mailing list)
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
Wes G. (Guest)
on 2006-05-16 23:35
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
Kirk H. (Guest)
on 2006-05-17 00:58
(Received via mailing list)
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.
Wes G. (Guest)
on 2006-05-17 01:19
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.
This topic is locked and can not be replied to.