A
A
Anton Ivanov2017-07-06 11:52:41
Ruby on Rails
Anton Ivanov, 2017-07-06 11:52:41

Why doesn't rails eager_load include classes with the same name but from different namespaces?

Hello.
There is an application and a gem that this application uses.
The gem has the following files
lib/provider1/class_name.rb

module Provider1
  class ClassName
    ...
  end
end

lib/provider2/class_name.rb
module Provider2
  class ClassName
    ...
  end
end

As you can see, the classes have the same name, but the namespace is different. config.eager_load_paths (in the engine.rb gem) specifies both directories. In development, everything works. In production, only the class from the directory specified first is automatically available.
What am I doing wrong?
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitri Sinitsa, 2017-07-06
@Fly3110

It seems to me that these directories should not be specified - just the "lib" directory itself is enough, then both classes will be available through their namespaces Provider1::ClassName, Provider2::ClassName. If you specify final directories, then it will load them into ClassName regardless of the namespace and then there will be a mess, because the class names are the same.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question