Currently, if we try to do something like this:
A = F::Container.new.tap do |container|
F::Container::Define.build(container: container).instance_exec do
namespace :math do
f(:value) { "A" }
end
end
end
B = F::Container.new.tap do |container|
F::Container::Define.build(container: container).instance_exec do
namespace :math do
f(:value) { "B" }
end
end
end
class Service
include A.import
include B.import
def call
f("math.value")
end
end
puts Service.new.() # => 'B'
Basically, if you try to import several containers the last one overrides all the previous ones.
But instead, we should make it work according to the following specification
Importing a container
We need to add a mechanism to store the imported containers in a box with assigned labels.
The first imported container gets the label main. Basically, the target class or a module should have a storage, like a hash, with labels as keys and with containers as values.
For example:
class Service
include A.import # this line should store { main: A }
def call
f('math.value') # => should work
f('main.math.value') # should also work
end
end
If one container is imported
- The behavior stays the same
** If several containers are imported
- An attempt to import a second module without an explicit alias should raise an error
class Service
include A.import # this line should store { main: A }
include B.import # this line should fail
include B.import.as(:second) # ok will work
end
- The function
f should look through the containers from top to bottom if there is no top namespace provided.
Currently, if we try to do something like this:
Basically, if you try to import several containers the last one overrides all the previous ones.
But instead, we should make it work according to the following specification
Importing a container
We need to add a mechanism to store the imported containers in a box with assigned labels.
The first imported container gets the label
main. Basically, the target class or a module should have a storage, like a hash, with labels as keys and with containers as values.For example:
If one container is imported
** If several containers are imported
fshould look through the containers from top to bottom if there is no top namespace provided.