DEV Community

Abdullah Al Mamun Fahim
Abdullah Al Mamun Fahim

Posted on

Release 0.3 #2

While I looking for my second issue I came across rails_icons. It reminded me of react-icons but for rails. Since I have have some experience in Ruby on rails and its been a while since I used it so I wanted to get some practice.

Approach

The issue is currently in order to use this gem the user must provide a set. Some supported libraries don't have multiple variants (maybe just “solid” or “outline”). Also any custom added library might not have one, giving the user mental overhead to come up with a name. So, the set parameter to initialize the RailsIcons::Icon instance. The issue includes all the places it is used.

Implementation

My first Idea was to set default value of set to nil. After that I had to update logic for everywhere @set is used. After looking at the code I noticed @set is not used directly. It is used by getter method set which returns the set value if its present else it'll return RailsIcons.configuration.default_set. I had to do some research on how to update the logic because now in initialize method @set can be "" if nil is passed. So now set method can return "" which didn't look right. So I wanted so that if @set is "" set method would return nil. And I found .presence helps me do the same thing. After that I put conditinal return statement in error_message, error_message and custom_library method. But custom_library was initially returning the set instead of the library. So I modified it to return library and in library_set_attributes I separately dig for set value. After I ran my changes I had to run bundle exec standardrb to fix the lint errors and rails test to run the test suit. Since I'm using WSL I has some issues running rails test. So I had to run bundle install. After that all the tests were passing.

The PR

Since I was done I made a PR. After making the PR the owner left some feedback requesting some changes. And once change I made was on thee conditional return statement had some code repetition. So putting arguments in an array and calling .compact_blank fix this issue leading to a single return statement. I also used splat operator to deconstruct the array to pass to respective user. As for other changes I made I left my explanation and additional questions. Currently awaiting response from the repo owner but I don't foresee any drastic changes being requested.

Conclusion

Working on a ruby project after taking a long break was refreshing. Since Ruby has a lot of use full methods & operator. There's always a method to help handle complex logic. Compared to hacktoberfest issues this was a lot more work with more work ahead. I definitely had to extend myself more on this release cycle.

Top comments (0)