Currently, the only way to define a container is using the DSL:
Using a global container
F.define do
namespace :hello do
f(:world) { -> { "Hello, world!" } }
end
end
Using a custom container
container = F::Container.new
F.define(container) do
namespace :hello do
f(:world) { -> { "Hello, world!" } }
end
end
The goal is to make the following code work:
# using inheritance
class MyContainer < F::Container::DSL
namespace :hello do
f(:world) { -> { "Hello, world!" } }
end
end
# or using extend, which I am leaning toward most
class MyContainer
extend F::Container::DSL
namespace :hello do
f(:world) { -> { "Hello, world!" } }
end
end
MyContainer['hello.world'].() #=> "Hello, world!"
class Service
include MyContainer.import(:hello)
def call
f(:word)
end
end
I was thinking about making fun_ruby fully compatible with the Rails environment and its autoloading features based on zeitwerk and the only way do that smoothly is to allow creating containers as constants
Currently, the only way to define a container is using the DSL:
Using a global container
Using a custom container
The goal is to make the following code work:
I was thinking about making fun_ruby fully compatible with the Rails environment and its autoloading features based on zeitwerk and the only way do that smoothly is to allow creating containers as constants