-
Notifications
You must be signed in to change notification settings - Fork 429
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
Use native String#end_with?, not the ActiveSupport wrapper #1905
Conversation
There is technically no need to depend on this core extension: https://github.com/rails/rails/blob/939fd3bc41bbb90194e4b93a001c803bdceb592c/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb
* Replace usage of `String#ends_with?` with `String#end_with?` to reduce the dependency on ActiveSupport core extensions. | ||
|
||
*halo* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I don't think this PR warrants an entry in the CHANGELOG, but it looked like one of the bot checks demanded it)
👍 If the two methods are totally equivalent, I see no reason to keep relying on ActiveSupport. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We make no guarantees around the dependency on ActiveSupport, but if there's an easy way to limit that dependency I see no reason not to approve it.
Thanks for the contribution!
Thanks for the very thorough PR description by the way, this is much appreciated and helps a lot when reviewing! |
When attempting to test integration between the gem and a real Rails app, I received a weird error coming from the `raise_if_slot_ends_with_question_mark` method inside the `view_component` gem. This didn't happen when I last tested the integration, which is very odd indeed. Relevant PR: ViewComponent/view_component#1905
There is technically no need to depend on this core extension: https://github.com/rails/rails/blob/939fd3bc41bbb90194e4b93a001c803bdceb592c/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb
There is technically no need to depend on this core extension: https://github.com/rails/rails/blob/939fd3bc41bbb90194e4b93a001c803bdceb592c/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb
When attempting to test integration between the gem and a real Rails app, I received a weird error coming from the `raise_if_slot_ends_with_question_mark` method inside the `view_component` gem. This didn't happen when I last tested the integration, which is very odd indeed. Relevant PR: ViewComponent/view_component#1905
When attempting to test integration between the gem and a real Rails app, I received a weird error coming from the `raise_if_slot_ends_with_question_mark` method inside the `view_component` gem. This didn't happen when I last tested the integration, which is very odd indeed. Relevant PR: ViewComponent/view_component#1905
What are you trying to accomplish?
I noticed a call to
String#ends_with?
, which is an ActiveSupport coreString
extension introduced in 2005.To reduce dependencies, I suggest using the ruby native
String#end_with?
(notice the missing "s") method instead. It's been in Ruby at least since 2.7.8.What approach did you choose and why?
I'm trying to create a gem that has some custom view components. Yet, I found no definite way to define the dependencies for a gem like mine. Some don't require
rails
at all, some require all ofrails
(evenactivejob
), some depend only onactionview
andactionsupport
, theview_component
gem itself only requires activesupport andactionview
implicitly (I'm not sure why).Having that in mind, I tried to not depend on the entirety of Rails, and a minimal test setup code like this was sufficient to create a test suite for my components:
However, my gem tests didn't pass because of this one call to
ends_with?
– yet, when I add the following line, all my tests naturally pass:Final thoughts
I know this is just a minimal change and maybe I'm foolish for not requiring all of Rails in my test suite. I'm also fully aware that in the future, I might not be able to use my approach any more, if more dependencies on Rails-internals are implicitly used inside of the view_component gem.
But at the very least, I thought, I'd be able to press the question of a canonical way to create gems that contain view components. If you tell me to load an entire rails dummy app in my test suite instead, then you can disregard this pull request :)
Thank you for your time. It's very exciting to see your gem develop from generation to generation.