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

Avoid duplication in r.bridgetown implementation #939

Merged

Conversation

jeremyevans
Copy link
Contributor

I apologize that I have not read the project goals, future roadmap, or code of conduct. If for any reason I'm violating something, please feel free to close.

This is a 🙋 feature or enhancement. It's actually a refactoring, but I think of removing duplication as an enhancement.

  • I've not added tests (if it's a bug, feature or enhancement). This is a refactoring and should not affect behavior.
  • I've not adjusted the documentation (if it's a feature or enhancement). This is a refactoring and should not affect behavior.
  • I've not run the test suite locally (I've forked the repo, but not even cloned it locally). However, I enabled GitHub Actions in my fork, and CI passed on my fork.

Summary

By choosing an appropriate argument to on, based on the base path, we don't need a separate if statement block and manual return.

Additionally, the nil at the end is not needed, as on will either throw if it handles the request, or return nil if it does not.

Context

I was reviewing the code as I'll be discussing it in an upcoming presentation, and came across this method, and saw an easy way to improve it.

By choosing an appropriate argument to `on`, based on the
base path, we don't need a separate if statement block and
manual return.

Additionally, the nil at the end is not needed, as `on` will either throw if it handles the request, or return nil if it does not.
@jaredcwhite
Copy link
Member

Hey @jeremyevans, thanks for this! Looks like a good way to avoid that duplication, and now I know a bit more about what on can do.

Also I'd love to learn more about your presentation, if/when possible!

@jaredcwhite jaredcwhite merged commit f081177 into bridgetownrb:main Nov 18, 2024
3 checks passed
@jeremyevans
Copy link
Contributor Author

Happy to help!

The presentation will be tomorrow at the SF Bay Area Ruby Meetup: https://lu.ma/f4pfsigc . It's mostly the same as my RubyConf presentation (https://code.jeremyevans.net/presentations/rubyconf2024/index.html), but since I have more time at the meetup, I'm adding Bridgetown as another example of an open source application that uses Roda.

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