OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
split up inflection method
ulferts34a61e62d006
diff --git a/config/constants/open_project/inflector.rb b/config/constants/open_project/inflector.rbnew file mode 100644index 00000000000..131eb44eecf--- /dev/null+++ b/config/constants/open_project/inflector.rb@@ -0,0 +1,39 @@+module OpenProject+ class Inflector < Zeitwerk::GemInflector+ alias_method :default_inflect, :camelize++ def camelize(basename, abspath)+ self.class.camelize_rules.each do |rule|+ name = instance_exec(basename, abspath, &rule)++ return name if name+ end++ super+ end++ private++ def overrides+ self.class.inflections.merge(super)+ end++ class << self+ def rule(&block)+ camelize_rules << block+ end++ def camelize_rules+ @camelize_rules ||= []+ end++ def inflections+ @inflections ||= {}+ end++ def inflection(overrides)+ inflections.merge!(overrides)+ end+ end+ end+enddiff --git a/config/initializers/zeitwerk.rb b/config/initializers/zeitwerk.rbindex 8ee9cb6501b..c61389026b4 100644--- a/config/initializers/zeitwerk.rb+++ b/config/initializers/zeitwerk.rb@@ -1,43 +1,55 @@-module OpenProject- class Inflector < Zeitwerk::GemInflector- # TODO: split up into a registry- def camelize(basename, abspath)- if basename =~ /\A(.*)_api\z/- super($1, abspath) + 'API'- elsif basename =~ /\Aoauth_(.*)\z/- 'OAuth' + super($1, abspath)- elsif basename =~ /\A(.*)_oauth\z/- super($1, abspath) + 'OAuth'- elsif basename =~ /\A(.*)_sso\z/- super($1, abspath) + 'SSO'- elsif basename =~ /\Aar_(.*)\z/- 'AR' + super($1, abspath)- elsif basename =~ /\Apdf_export\z/- 'PDFExport'- elsif abspath =~ /open_project\/version(\.rb)?\z/- "VERSION"- else- super- end- end+require Rails.root.join('config/constants/open_project/inflector')++OpenProject::Inflector.rule do |_, abspath|+ if abspath.match?(/open_project\/version(\.rb)?\z/)+ "VERSION"+ end+end++OpenProject::Inflector.rule do |basename, abspath|+ if basename =~ /\A(.*)_api\z/+ default_inflect($1, abspath) + 'API'+ end+end++OpenProject::Inflector.rule do |basename, abspath|+ if basename =~ /\Aar_(.*)\z/+ 'AR' + default_inflect($1, abspath)endend+OpenProject::Inflector.rule do |basename, abspath|+ if basename =~ /\Aoauth_(.*)\z/+ 'OAuth' + default_inflect($1, abspath)+ elsif basename =~ /\A(.*)_oauth\z/+ default_inflect($1, abspath) + 'OAuth'+ elsif basename == 'oauth'+ 'OAuth'+ end+end++OpenProject::Inflector.rule do |basename, abspath|+ if basename =~ /\A(.*)_sso\z/+ default_inflect($1, abspath) + 'SSO'+ end+end++OpenProject::Inflector.inflection(+ 'api' => 'API',+ 'rss' => 'RSS',+ 'sha1' => 'SHA1',+ 'sso' => 'SSO',+ 'csv' => 'CSV',+ 'pdf' => 'PDF',+ 'scm' => 'SCM',+ 'imap' => 'IMAP',+ 'pop3' => 'POP3',+ 'openid_connect' => 'OpenIDConnect',+ 'pdf_export' => 'PDFExport'+)+Rails.autoloaders.each do |autoloader|autoloader.inflector = OpenProject::Inflector.new(__FILE__)- autoloader.inflector.inflect(- 'api' => 'API',- 'rss' => 'RSS',- 'sha1' => 'SHA1',- 'oauth' => 'OAuth',- 'sso' => 'SSO',- 'csv' => 'CSV',- 'pdf' => 'PDF',- 'scm' => 'SCM',- 'imap' => 'IMAP',- 'pop3' => 'POP3',- 'openid_connect' => 'OpenIDConnect'- )end# Instruct zeitwerk to ignore all the engine gems' lib initialization filesdiff --git a/lib/open_project/plugins/acts_as_op_engine.rb b/lib/open_project/plugins/acts_as_op_engine.rbindex 5dbae38a845..399f8baab18 100644--- a/lib/open_project/plugins/acts_as_op_engine.rb+++ b/lib/open_project/plugins/acts_as_op_engine.rb@@ -285,6 +285,21 @@ module OpenProject::Pluginsrepresenter_class.prepend modendend++ # Add custom inflection for file name to class name mapping. Otherwise, the default zeitwerk+ # #camelize method will be utilized.+ #+ # class_inflection_override('asap' => 'ASAP')+ #+ # inflector.camelize("asap", abspath) # => "ASAP"+ #+ # @param overrides [{String => String}]+ # @return [void]+ def class_inflection_override(overrides)+ self.class.initializer "#{engine_name}.class_inflection_override" do+ OpenProject::Inflector.inflection(overrides)+ end+ endendendenddiff --git a/modules/openid_connect/lib/open_project/openid_connect/engine.rb b/modules/openid_connect/lib/open_project/openid_connect/engine.rbindex 9a6510b81b7..d2bc352e018 100644--- a/modules/openid_connect/lib/open_project/openid_connect/engine.rb+++ b/modules/openid_connect/lib/open_project/openid_connect/engine.rb@@ -24,6 +24,8 @@ module OpenProject::OpenIDConnectopenid_connect/auth_provider-heroku.png)+ class_inflection_override('openid_connect' => 'OpenIDConnect')+register_auth_providers do# Use OpenSSL default certificate store instead of HTTPClient's.# It's outdated and it's unclear how it's managed.