Let’s say I’m working on a product called Friendly Organizational Operator, for which we use FOO as the acronym. I want to create a new engine to encapsulate a particular piece of functionality we’ll call Bar (I used all my creativity on that first one). Naturally, my engine will be called
foo-bar with a namespaced name of
foo/bar. However, the root module name will be
Foo, when in reality I’d really like it to be
FOO. For example:
$ rails plugin new foo-bar --mountable create create README.md create Rakefile create foo-bar.gemspec create MIT-LICENSE create .gitignore <...snip...> $ cat foo-bar/lib/foo/bar/engine.rb module Foo module Bar class Engine < ::Rails::Engine isolate_namespace Foo::Bar end end end
I realize that I need to actually tell Rails about this acronym. Generally I do that with an initializer in the engine:
module FOO module Bar class Engine < ::Rails::Engine isolate_namespace FOO::Bar initializer 'setup_inflections' do ActiveSupport::Inflector.inflections do |inflect| inflect.acronym 'FOO' end end end end end
Then the rest falls into place just fine (e.g. autoloading). Of course, I need to run a big sed search/replace on the entire engine first.
So here’s my question: is there a way for me to generate that initial engine using the proper acronym off the bat instead of needing to sed after I’ve created it? As it happens I’m using application templates anyway, so I’m just doing the sed in there, but I’m not a huge fan. Can I tell Rails about my acronym before it generates the engine? Perhaps there is some functionality in the application template API that I’ve missed? A hook that might run before the actual generation, maybe (otherwise my template always runs after the engine is already generated)?
Thanks for your time!