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-on constants are not namespaced #562
Comments
Or less drastically, use methods/class instance attributes instead of consts. That would just call for something like a rubocop cop to check for const assignment outside of real class/module scopes. |
The bad part is that the DSL has been given as THE interface to develop external addons with. Is it not possible to dynamically also create the namespace for the add-on classes? |
So, add Rubocop as a runtime dependency and somehow run it against the addons before Or "something like rubocop", meaning something like ruby2ruby and analyze the sexp thing. Probably easier to just tell the users to do |
Classes get their name when you assign the class to a constant, except if doing that via Foo = Class.new { puts "#{name}" } # => Foo
Addons.const_set(:Foo, Class.new { puts "#{name}" } # => Dynamic constant assignment is not something that is supposed to be done, I guess. The anonymous classes do have their own constant namespaces that you can use like:
But this would then make the DSL mostly ruby, but have this strange quirk "if you use constants, use Getting rid of the DSL means that you have to change one line of your DSL: - Pharos.addon "ingress-nginx" do
+ class IngressNginx < Pharos::Addon (the addon name can be set via a method or inflected from the class name through some sort of |
In the light of this, I find it very strange that the https://github.com/kontena/pharos-cluster/blob/master/spec/pharos/addons/ingress_nginx_spec.rb#L47 passes on travis. It never does on my machine. The The correct const in this case would be |
It would be possible to parse the addon files, get the content between This would keep the current "api" but define the addons as regular classes instead of anonymous ones. |
Due to the way the DSL is creating classes, they do not have a namespace during definition.
This means that any duplicate constants will generate a
warning: already initialized constant
and change the value globally.The best solution, I think, is to get rid of the addon DSL.
The text was updated successfully, but these errors were encountered: