Last Updated: February 25, 2016
·
3.242K
· cutalion

Sort gems in your Gemfile

Select gems in the Gemfile and sort them

:'<,'>!sort

8 Responses
Add your response

oO

This assumes three things:

1) You're not using any group blocks
2) Your gems do not have require order dependencies (client_side_validations and its plugins come to mind)
3) You want your gems sorted rather than organized by similarity.

over 1 year ago ·

Make sure you understand what does '<,'> mean ;)

over 1 year ago ·

Yes, I know what '<,'> means @cutalion. So you're suggesting sorting subsets of gems. No problem, my rules to the subsets you can select/sort. I'm just saying it's dangerous... use with caution :)

over 1 year ago ·

Why would you want to sort your Gems? Usually (as pointed out above) they're in groups. Sometimes they're also sorted according to purpose.

over 1 year ago ·

@descentintomael, why not? I found it quite handy to have sorted groups of gems in large Gemfile.

For instance, take a look at catarse project's Gemfile
and at the version with sorted gems in groups. At the first sight there is no difference, but I believe that the additional rule (or convention) reduces the chaos in that file. Of course it should be a team decision.

over 1 year ago ·

That makes sense. I thought your original idea was to sort all the gems in the top-level of the Gemfile.

over 1 year ago ·

If you just need a sorted list of all your gems, you can try this script http://rbjl.net/63-what-s-in-your-gemfile with the --sorted option

over 1 year ago ·

@janlelis, nice script! Not sure I'll use it to keep a sorted list of gems - it adds a lot of noise to Gemfile. Overall, I like it, it could save some time.

over 1 year ago ·