Skip to content

Commit 0dfcf8a

Browse files
committed
SolidusAdmin: Configure generator namespace early in generator
A previous solution for this bug tried to set the generator namespace in an app initializer, but that required `rails/generators/base` to be required - which it is not always when starting up e.g. a server. I've tried to dig a bit into how this `mattr_accessor :namespace` on `Rails::Generators::Base` is supposed to be used. It seems like it is run when loading an engine's generators here[1], but that does not work in this context. I don't fully understand how Rails::Generators.namespace is supposed to be set, but this at least sets it only when needed. There's probably some magic that we could invoke, but I can't find it documented anywhere. [1] https://github.com/rails/rails/blob/main/railties/lib/rails/command/actions.rb#L38
1 parent e5ed0ff commit 0dfcf8a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

admin/lib/generators/solidus_admin/component/component_generator.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class ComponentGenerator < Rails::Generators::NamedBase
1212
class_option :spec, type: :boolean, default: true
1313
class_option :preview, type: :boolean, default: true
1414

15+
def setup_namespace
16+
Rails::Generators.namespace = SolidusAdmin
17+
end
18+
1519
def setup_inflections
1620
# This is needed because the generator won't run the initialization process,
1721
# in order to ensure that UI is not rendered as Ui we need to setup inflections

0 commit comments

Comments
 (0)