-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Instantiated inflector objects are not configurable #44
Comments
Hi, previous year me and Piotr had a conversation about removing the default inflections and having a |
I would start from extending functionality with backward compatibility fully kept. The other idea from solnic could be, if we make inflections public, to have a #finalize method that would freeze the object from further modifications. |
I don't like an idea of having an explicit finalize method in this case as it makes the configuration pretty unpredictable when used inside other framework and force having an additional step for standalone usage |
Agree. The Then we would need to yet tweak docs a little bit to include the best practices for gems |
This wouldn't be a regular way of using it but in a framework reality, where it controls what happens, this makes sense. An inflector could be exposed to anything that may need it so that external components could configure it according to their requirements, and then the framework would finalize it to prevent further changes. This is how it works in case of dry-configurable and we already went through the "don't allow changing it" phase with this gem and it was quite problematic and inconvenient. |
Can we then set consensus, that the expected solution would be:
|
I still heavily don't like |
We can just use |
Hey guys 👋 While migrating a project to Hanami 2 I faced the issue with constants like:
Zeitwerk would accuse an error like:
I understand that |
@solnic Sorry for pinging you so often, but I just realized that we may add an option to not load default inflections besides the very basic once, like: inflector = Dry::Inflector.new(load_defaults: false) do |inflections| |
Any update on this? I am a fan of the load_defaults flag, and am currently running into this issue. |
Describe the bug
The current way to configure inflector object is as follows:
This has some caveats though
2.plural/singular/acronym methods are called on inflections.
this makes it troublesome to extend pre-confiured inflections for existing libraries like ROM in example:
https://github.com/rom-rb/rom/blob/release-5.2/core/lib/rom/support/inflector.rb
To extend exiting Inflector, we need to either override the existing inflector duplicating it's rules, or access inflections private methods - both ways seem to be weird.
To Reproduce
Expected behavior
I expect to have a way of extending exiting inflector.
inflections
as public methodsDry::Inflector.extend(existing_inflector) do |inflections|
- that could copy existing inflection rules.Then I expect documentation to clearly describe how to aproach such situations, to avoid producing Ruby gems that are
I have some concerns against just making
inflections
public, as I very much like to see inflector object as an injectable, frozen dependency that people cannot change at runtime.My environment
Note
PS: I'm happy to come up with a PR once we'll clarify the preferrable solution.
The text was updated successfully, but these errors were encountered: