Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a superclass/module for containers to allow defining containers as classes #7

Open
woarewe opened this issue Feb 17, 2023 · 0 comments

Comments

@woarewe
Copy link
Owner

woarewe commented Feb 17, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant