Renaming Journey and avoiding libraries with common noun names

Probably a stupid solution, but rather than suggesting non-common noun names, why not suggest to put it in a module like Rails::Journey (or whatever would make sense)?

That alone doesn’t solve your issues, but if you don’t mind really messing with the way Rails resolves constants, you could use something like these: https://github.com/garysweaver/classmeta/blob/v0.1.0/lib/classmeta/class_registry.rb https://github.com/garysweaver/classmeta/blob/v0.1.0/lib/classmeta/dependencies.rb

(not the classmeta gem, but that method of placing a layer of constant resolution between your app and rails.)

That isn’t efficient and still doesn’t help, but if you took that yet another step further, you could change autoloading such that it keeps track of whether the class was loaded locally or not, and if it was, it would use your Journey class, otherwise it would use some other gem’s Journey. You could generify the gem and call it StevePerry or maybe just Perry. Hmm… might do that later.

Your concern is sane, but attempting to change the developer tendency to call things by great band names seems like it might be a problem.

As usual though, I’m probably wrong. Way wrong. In the worst of ways.

Darn, that name was already taken. Looks like a nice project: perry | RubyGems.org | your community gem host

Ok, this is not done/working yet, but is a start. Was thinking that maybe looking at caller stack might be better to attempt to determine whether class is being referenced locally, so not messing with autoload. However, I have a feeling this won’t work unless the Journey constant is uncached on each reference. My daughter is extremely bored waiting on me currently, so gotta run for now:

Got constance working and it is sweet like candy (like old-tyme candy back before they knew how to make candy, so forgive me if it sucks). This might solve the common-noun constant problem. Try it out and let me know.

Looks like it still needs some work. It works with resolving other classes, but even if I try to remove Journey from the class cache with: ActiveSupport::Dependencies::Reference.clear!

that doesn’t work. Oh well, sorry. It makes a decent dependency debugger though.

Ah. Wasn’t thinking that the constants in ActiveSupport::Dependencies::Reference don’t include everything. :slight_smile:

Needed to store the class for later retrieval and then: Object.send(:remove_const, :Journey)

I think may be fixed in current version of Constance gem. Try: Constance::Resolver.will_replace(Journey)

Unfortunately the example search regexps on the caller stack may be inadequate because lib is in just about every gem so would need to prefix with your app name.