Contributing to Open Source

Dec 21, 2023
Open source runs the internet, it's the web's bloodstream that we've all fed from. And right on this first paragraph I'd like to express my gratitude to all individuals and businesses that have dedicated their time and resources to advancing the web with open source. I'm particularly grateful to DHH and the 37signals team for their consistent and unwavering support for OSS, and all their really good open source gifts to us

I haven't contributed to open source as much as I'd love to, but for the handful gems/libraries I have contributed to, I am super proud. And I am, with lots of enthusiasm and excitement, waiting to contribute more in the near future when I finally can.

My latest contribution was to the cloudflare gem that I'm using at Headportfolio to have support for  subdomains and custom domains for new online portfolios my users create.

Every online portfolio our users create with us has a unique name that we use to create a subdomain for on Cloudflare. When they update that unique name, I'd like to update their subdomain on Cloudflare as well, to use the new name.

Cloudflare has an API for that and other functionalities, but it was easier to use the gem as it had all the other functionalities  I needed, except the ability to update all the values of a DNS record, which I would need when updating people's subdomains.

To figure out what needed to be done, I dug into the gem's source and found that they already had an `update_content` method that allowed updating the content of a DNS record, but I needed more than just updating the DNS record content.

So I created a new `update` method that lets you pass all the parameters of a DNS record - the type, name, content and options - a hash with extra params such as `proxied: true/false`.

Screenshot 2023-12-21 at 13.35.57.png 85.7 KB

Screenshot 2023-12-21 at 13.33.39.png 68.2 KB

Of course I tested the new functionality using RSpec, can't skip tests!

That would have done it, but I spotted a few areas I could improve in the gem. First, it took me a couple of minutes to set the gem locally and make it ready for development, because it needed me to set up some environment variables for accessing Cloudflare.

To help the next person speed up their setup, I added the dotenv gem so that environment variables can be loaded from a .env file, which is kinda the norm nowadays. I then created a .env.example file with the expected environment variables and added a step on the readme to create the .env file prepopulated with the env variables in the example file.

While testing the new method I added, I also needed to set up breakpoints so I could do more introspection, but the gem wasn't set up with the pry gem, so I set it up as well.

And while on my way out, I noticed two RSpec shared contexts written in the spec_helper.rb file, so to help clean things a bit, I moved them into a new `spec/support` directory, much neater!

And that was it, less than a day's work and the internet was left at a much better place!

My PR is still waiting for review, feel free to check it out and share feedback. Fingers crossed the maintainers will find my changes beneficial and this will make it way upstream. But until then, let's continue supporting all our open source software and being friendly to the maintainers!

Screenshot 2023-12-21 at 13.31.11.png 392 KB

Thank you once again to the OS world and all the maintainers.

Happy Holidays!

christmas.jpg 1.36 MB