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

Issues with inflection AU #410

Open
gamecreature opened this issue Sep 5, 2023 · 1 comment
Open

Issues with inflection AU #410

gamecreature opened this issue Sep 5, 2023 · 1 comment

Comments

@gamecreature
Copy link

gamecreature commented Sep 5, 2023

In pull request #332, an acronym inflection is added to support the incorrect class name Spree::GateWay::SecurePayAU (app/models/spree/gateway/secure_pay_au.rb).

Because Zeitwork doesn't like the naming scheme of SecurePayAU.
This inflection causes unexpected behavior when using .titleize on a string.

Due to this change the the brand WALDLAUFER is titleized Waldl AU Fer.
This inflection also causes Zeitwerk issues on every AU classname.

If the capitalized AU is important, (for backwards compatibility).
Isn't it a better solution to just add alias for this class.

Solution

I think best solution is to remove the inflection and rename the class from SecurePayAU to SecurePayAu. Of course this can/will be an issue with existing installations.

Backwards compatibility Solution

Another solution is the following

Remove the inflection: config/initializers/inflections.rb

# DELETE: inflect.acronym 'AU'

Rename the class and add an alias for the class to app/models/spree/gateway/secure_pay_au.rb, so it follows the Zeitwerk naming

module Spree
  class Gateway::SecurePayAu < Gateway
    #... 
  end
  Gateway::SecurePayAU = Gateway::SecurePayAu
end

In the lib/spree_gateway/engine.rb register both classes OR use the following construct to load the legacy classname.

Spree::Gateway::SecurePayAu 
app.config.spree.payment_methods << Spree::Gateway::SecurePayAU
@gamecreature
Copy link
Author

gamecreature commented Sep 5, 2023

Maybe another way is to adjust the inflector only for the autoloader (and not for the whole ActiveSupport scope). (See rails guide https://guides.rubyonrails.org/classic_to_zeitwerk_howto.html#acronyms)

Rails.autoloaders.main.inflector.inflect("vat" => "VAT")

In this situation the name would be

Rails.autoloaders.main.inflector.inflect("secure_pay_au" => "SecurePayAU")

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