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

[Feat] Rails integration to set default inflector #298

Merged
merged 1 commit into from
Feb 3, 2023
Merged

Conversation

okuramasafumi
Copy link
Owner

This is a temporary implementation of how to automatically set default inflector with Rails.
I haven't tested with user-defined inflector setting.

@codecov
Copy link

codecov bot commented Jan 21, 2023

Codecov Report

Merging #298 (d5e1e85) into main (4931e17) will decrease coverage by 0.06%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #298      +/-   ##
==========================================
- Coverage   99.18%   99.13%   -0.06%     
==========================================
  Files          12       13       +1     
  Lines         489      576      +87     
==========================================
+ Hits          485      571      +86     
- Misses          4        5       +1     
Impacted Files Coverage Δ
lib/alba.rb 100.00% <100.00%> (ø)
lib/alba/railtie.rb 100.00% <100.00%> (ø)
lib/alba/resource.rb 99.37% <0.00%> (-0.21%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@trevorturk
Copy link
Collaborator

trevorturk commented Jan 21, 2023

This seems fine to me as an alternative to #274. You could consider Alba.inflector ||= :active_support in case the user somehow wants to set it a different way and this runs first. Note in the other PR I did before_initialize, but I think this is fine and probably more typical anyway.

If you want help testing, let me know. I have a few sample Rails and Hanami apps I was using to test this earlier as well.

This is an implementation of how to automatically
set default inflector with Rails.
I haven't tested with user-defined inflector setting.
@okuramasafumi
Copy link
Owner Author

@trevorturk I think this works OK, could you try it in real Rails apps? If this works I'll add Hanami integration in separate PR.

@trevorturk
Copy link
Collaborator

Yes, this works perfectly for me. It's set by default, and if you want to configure Dry::Inflector it works as well:

irb(main):001:0> Alba.inflector
=> Alba::DefaultInflector

#...and with
# config/initializers/alba.rb
Alba.inflector = :dry

irb(main):001:0> Alba.inflector
=> #<Dry::Inflector>

@okuramasafumi
Copy link
Owner Author

@trevorturk Could you also check if it works with user-defined initializer? For example,

# config/initializers/alba.rb
Alba.inflector = :dry

@trevorturk
Copy link
Collaborator

Yes, sorry if I wasn't clear about it, but I did test that. (See my code sample above, I should have broken it into two examples, but I did try with and without an initializer. It works great in both cases.)

@okuramasafumi
Copy link
Owner Author

Awesome, thank you!

@okuramasafumi okuramasafumi merged commit 3afd032 into main Feb 3, 2023
@okuramasafumi okuramasafumi deleted the railtie branch February 3, 2023 09:21
@trevorturk
Copy link
Collaborator

🥳

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

Successfully merging this pull request may close these issues.

2 participants