<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Stefan Wrobel</title>
    <description>The latest articles on DEV Community by Stefan Wrobel (@swrobel).</description>
    <link>https://dev.to/swrobel</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F310302%2F676f56ad-401f-4f00-8760-c452fed6b187.jpeg</url>
      <title>DEV Community: Stefan Wrobel</title>
      <link>https://dev.to/swrobel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/swrobel"/>
    <language>en</language>
    <item>
      <title>Bundle Everything</title>
      <dc:creator>Stefan Wrobel</dc:creator>
      <pubDate>Wed, 23 Aug 2023 23:47:31 +0000</pubDate>
      <link>https://dev.to/swrobel/bundle-everything-4fkc</link>
      <guid>https://dev.to/swrobel/bundle-everything-4fkc</guid>
      <description>&lt;h2&gt;
  
  
  &lt;em&gt;or: how I learned to stop worrying and ditch gemsets for good&lt;/em&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  tl;dr
&lt;/h3&gt;

&lt;p&gt;If you don't use gemsets and are just interested in my bundler flow, skip to the Bundler workflow section.&lt;/p&gt;

&lt;h3&gt;
  
  
  Background
&lt;/h3&gt;

&lt;p&gt;In my previous post about &lt;a href="https://dev.to/rvm-implode"&gt;switching from rvm to ruby-install and chruby&lt;/a&gt;, I mentioned that my primary motivation for switching away from &lt;a href="https://rvm.io/"&gt;rvm&lt;/a&gt; is runaway gemset disk usage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rvm disk-usage gemsets
Gemsets Usage: 5.4G
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'm generally working on a bunch of different ruby projects at once, and like every good rvm user, I would create a new gemset when I started or cloned the project because ... well, that's what you do! But the problem is that there's no straightforward way to eliminate orphan gemsets when &lt;code&gt;rm&lt;/code&gt;ing the project directory, and so you're left with 5.4GB of gemsets and you have no idea whether those are even relevant anymore.&lt;/p&gt;

&lt;p&gt;Enter &lt;a href="http://bundler.io/"&gt;bundler&lt;/a&gt;, the tool that seems to become more and more magical with each version. You're probably already using bundler (if you aren't, WHAT?!) but letting it install into rvm's gemset folder hierarchy rather than directly into your project's directory. It's time to change that in just a few easy steps!&lt;/p&gt;

&lt;p&gt;Inspired by Ryan McGeary's excellent &lt;a href="http://ryan.mcgeary.org/2011/02/09/vendor-everything-still-applies/"&gt;"Vendor Everything"&lt;/a&gt; post from 2011, I set out to come up with my own bundler workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bundler workflow
&lt;/h2&gt;

&lt;p&gt;I've configured bundler to install gems to my project's &lt;code&gt;vendor/bundle&lt;/code&gt; directory. That way, if I remove the project directory, all of the gems that I've installed specifically for it are gone as well. No more hunting down orphaned gemsets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bundle config --global path vendor/bundle
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells bundler to install gems to &lt;code&gt;vendor/bundle&lt;/code&gt; by default (rather than your global gem store). You can of course always install gems that you need globally (like bundler) by using &lt;code&gt;gem install&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Rails 4+ will generate binstubs for &lt;code&gt;rails&lt;/code&gt;, &lt;code&gt;rake&lt;/code&gt; and &lt;code&gt;bundle&lt;/code&gt; to &lt;code&gt;bin/&lt;/code&gt;. With binstubs, you can run &lt;code&gt;bin/rake&lt;/code&gt; instead of &lt;code&gt;bundle exec rake&lt;/code&gt;, for example. If you want to make it really simple, just add &lt;code&gt;./bin&lt;/code&gt; to the front of your $PATH and your shell will always look there first. To generate binstubs for any other gems, like spring, just run &lt;code&gt;bundle binstub &amp;lt;gemname&amp;gt;&lt;/code&gt; and it will create one in &lt;code&gt;bin/&lt;/code&gt; for you.&lt;/p&gt;

&lt;p&gt;This is a little bit tricky with &lt;a href="https://github.com/postmodern/chruby"&gt;chruby&lt;/a&gt; because it always puts its gem bin directory at the front of $PATH so you need to add it in an after hook, which isn't officially supported. &lt;a href="https://github.com/postmodern/chruby/wiki/Implementing-an-'after-use'-hook#zsh-5x"&gt;This&lt;/a&gt; is how I accomplished that with my zsh/chruby setup.&lt;/p&gt;

&lt;p&gt;You'll also want to add the following line to your &lt;code&gt;.gitignore&lt;/code&gt; if it isn't there already:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/vendor/bundle
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Bonus points: parallelize bundler
&lt;/h3&gt;

&lt;p&gt;First, make sure you update to bundler &amp;gt;= 1.5.0&lt;/p&gt;

&lt;p&gt;If you're using Linux, run &lt;code&gt;nproc&lt;/code&gt;. If you're using a Mac, run &lt;code&gt;sysctl -n hw.ncpu&lt;/code&gt;. If you're using Windows, then god help you...&lt;/p&gt;

&lt;p&gt;Take the output of that command and replace the X below with it. This will tell bundler to always spawn X number of processes to install gems in parallel. Your &lt;code&gt;bundle install&lt;/code&gt; runs will be &lt;em&gt;much&lt;/em&gt; faster.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bundle config --global jobs X
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ruby</category>
      <category>bundler</category>
    </item>
    <item>
      <title>rvm implode</title>
      <dc:creator>Stefan Wrobel</dc:creator>
      <pubDate>Wed, 23 Aug 2023 23:44:03 +0000</pubDate>
      <link>https://dev.to/swrobel/rvm-implode-4b75</link>
      <guid>https://dev.to/swrobel/rvm-implode-4b75</guid>
      <description>&lt;h2&gt;
  
  
  tl;dr
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;rvm implode &amp;amp;&amp;amp; brew install chruby &amp;amp;&amp;amp; brew install ruby-install&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;As a ruby developer, I grew to love &lt;a href="https://rvm.io/"&gt;rvm&lt;/a&gt;. It does so much it seems like magic ... in fact, it may actually be magic. But after a multi-year love affair, its flaws became apparent.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rvm disk-usage gemsets
Gemsets Usage: 5.4G
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Yikes.&lt;/em&gt; My first thought was to try to figure out how much disk space each individual gemset was using and remove some of them. I read the docs and didn't find anything there, so I went to the &lt;a href="https://groups.google.com/d/topic/rubyversionmanager/-shEn7e1Li4/discussion"&gt;mailing list&lt;/a&gt;, and &lt;a href="https://twitter.com/mpapis"&gt;mpapis&lt;/a&gt;, being the amazing guy that he is, got back to me right away. Alas, no simple way to do this.&lt;/p&gt;

&lt;p&gt;Then I started to think a little bit more about why I was even using gemsets. Typing &lt;code&gt;bundle exec&lt;/code&gt; can get pretty annoying, but it isn't the end of the world. I had a separate gemset for each app to keep my gem dependencies from conflicting, but that's what bundler is for. What really annoyed me was that when I would &lt;code&gt;rm -rf&lt;/code&gt; an app's code, I'd forget to remove the gemset and I had a bunch of orphaned gemsets out there hogging disk space.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rvm implode&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The many talents of rvm
&lt;/h2&gt;

&lt;p&gt;Like I mentioned, rvm does a lot:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Compilation/installation of rubies&lt;/li&gt;
&lt;li&gt;Switching between rubies&lt;/li&gt;
&lt;li&gt;Separation of gem dependencies&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The problem is that it's trying to be all things to all people. There are some 20,000 lines of shell script in rvm, and each of these things can be accomplished much more efficiently by a single purpose-built tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. s/rvm/ruby-install
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;brew install ruby-install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For installing rubies, I'm using &lt;a href="https://github.com/postmodern/ruby-install"&gt;ruby-install&lt;/a&gt;, written by the amazing &lt;a href="https://twitter.com/postmodern_mod3"&gt;postmodern&lt;/a&gt;. There's also &lt;a href="https://github.com/sstephenson/ruby-build"&gt;ruby-build&lt;/a&gt; which works almost as well, but I love the fact that ruby-install lets me use shortcuts like I did with rvm so I can just do &lt;code&gt;ruby-install ruby 2.0&lt;/code&gt; and get the latest 2.0 patchlevel rather than having to specify manually like with ruby-build.&lt;/p&gt;

&lt;p&gt;ruby-install is dead-simple and does exactly what it promises. By default it installs rubies to &lt;code&gt;~/.rubies&lt;/code&gt; although you can install them wherever your heart desires. I stuck with the default.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. s/rvm/chruby
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;brew install chruby&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For switching rubies, I'm using &lt;a href="https://github.com/postmodern/chruby"&gt;chruby&lt;/a&gt;, again, by the unstoppable &lt;a href="https://twitter.com/postmodern_mod3"&gt;postmodern&lt;/a&gt;. Some folks prefer &lt;a href="https://github.com/sstephenson/rbenv"&gt;rbenv&lt;/a&gt;, but I love the simplicity of chruby. Plus, it (optionally) does auto-switching like rvm, so if a directory has a &lt;code&gt;.ruby-version&lt;/code&gt; file, it will switch to that version automagically.&lt;/p&gt;

&lt;p&gt;chruby will automatically look in &lt;code&gt;~/.rubies&lt;/code&gt;, where ruby-install puts them, so no configuration needed there. just add three lines to your &lt;code&gt;.bashrc&lt;/code&gt; or &lt;code&gt;.zshrc&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source&lt;/span&gt; /usr/local/opt/chruby/share/chruby/chruby.sh &lt;span class="c"&gt;# mandatory&lt;/span&gt;
&lt;span class="nb"&gt;source&lt;/span&gt; /usr/local/opt/chruby/share/chruby/auto.sh &lt;span class="c"&gt;# if you want auto-switching&lt;/span&gt;
chruby ruby-2.0 &lt;span class="c"&gt;# to set a default ruby&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ruby</category>
      <category>rvm</category>
      <category>chruby</category>
    </item>
  </channel>
</rss>
