<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>INTERSECT</title>
    <description>Championing the Ruby-Powered Open Web</description>
    <link>https://intersect.whitefusion.io/</link>
    <atom:link href="https://intersect.whitefusion.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Fri, 05 Feb 2021 00:44:08 +0000</pubDate>
    <lastBuildDate>Fri, 05 Feb 2021 00:44:08 +0000</lastBuildDate>
    <generator>Jekyll v3.6.2</generator>
    
      <item>
        <title>The Archival Benefits of Static Site Generators</title>
        <description>&lt;img src="https://intersect.whitefusion.io/assets/history-and-time.jpg"&gt;&lt;h2&gt;If you value the content you publish and want your sites to remain accessible many decades from now, then it’s time to go static.&lt;/h2&gt;&lt;p&gt;I’ve been on a nostalgia trip lately, poring over old snapshots of various sites and blogs I worked on in the past (stretching all the way back to 1996). &lt;a href=&quot;https://jaredwhite.com/articles/thank-goodness-for-the-wayback-machine&quot;&gt;Thank goodness for the Wayback Machine!&lt;/a&gt; But it’s gotten me thinking about the impermanence of the digital artifacts we create all the time as designers, developers, and content authors.&lt;/p&gt;

&lt;p&gt;All the work you’ve put into that app, that blog post, that video, that Instagram story…blink and it’s gone! In some cases that’s by design. Content that expires and is quickly forgotten has become desirable in certain circles, the artform being all about its “in the moment”-ness.&lt;/p&gt;

&lt;p&gt;But in the instances where you want to preserve your content for posterity, the options become challenging. Let’s focus on blogging for the sake of this discussion. I’ve run a number of blogs over the years, and I deeply care about preserving those—at the very least for myself but also for my children and their children (etc.). But the sad truth of the matter is that I’ve “lost” almost all of them. They’re either folders of PHP spaghetti code or SSI files (Server-Side Includes…remember those?) or WordPress installations scattered across multiple ancient backup drives—some of which are in formats or using connectors can’t even use any more. Plus in many cases the content itself doesn’t even live in those folders, but rather exists in old MySQL databases which I would have to track down, load up, and possibly convert in order to access any of that content!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bottom line:&lt;/strong&gt; I’m essentially forced to rely on the Wayback Machine to look up my old content, but not all of the posts and domains were properly archived—and on many of the pages that do work, image links are often broken. It’s hardly an ideal scenario.&lt;/p&gt;

&lt;h3 id=&quot;there-is-a-better-way-make-your-site-static&quot;&gt;There is a Better Way: Make Your Site Static&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Thankfully&lt;/em&gt;, I’m now building all of my sites (including this one!) in a completely new way. I’m using &lt;a href=&quot;https://jekyllrb.com&quot;&gt;Jekyll&lt;/a&gt;, which is a Static Site Generator. What does that mean? It means the content for the site—both the blog posts and pages as well as all of the template &amp;amp; layout files, Javascript code, and stylesheets—lives entirely within a simple folder hierarchy and consists solely of plain text files (other than images and other media of course). No databases to install, no weird dynamic code to run on the fly. All you have to do is run &lt;code class=&quot;highlighter-rouge&quot;&gt;jekyll build&lt;/code&gt; at the command line (or in my case &lt;code class=&quot;highlighter-rouge&quot;&gt;gulp build ; jekyll build&lt;/code&gt; because I process the source SCSS and JS files with &lt;a href=&quot;https://gulpjs.com/&quot;&gt;Gulp&lt;/a&gt;) and in seconds you get a &lt;code class=&quot;highlighter-rouge&quot;&gt;_site&lt;/code&gt; folder with your complete website generated and ready to deploy and view anywhere. As long as you write your content in Markdown (.md) or HTML (.html), you’re golden.&lt;/p&gt;

&lt;p&gt;But the special one-two punch of using a Static Site Generator such as Jekyll is the fact that you can save your site and all of its content into a version controlled repository. Once your site is stored in a Git repo, you have endless options for how you want to archive and protect your data. Not only do you have every version of your site archived within the repo (so you can “go back in time” to view past iterations of the site), you can easily store the repo in multiple places at once. All of my sites are stored both locally on my computer as well as “in the cloud” in Bitbucket or GitHub, and in some cases they’re also stored on DigitalOcean servers I’ve set up with custom web apps I use to manage the content files using WYSIWYG editing tools. If my computer is busted, my sites are safe online, and if the internet completely goes down, at least I still have my local copies.&lt;/p&gt;

&lt;p&gt;Why is this all so important for archival purposes? Here are three big reasons:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;You can view your site without any special software.&lt;/strong&gt; Just fire up the most basic web server imaginable, drop your &lt;code class=&quot;highlighter-rouge&quot;&gt;_site&lt;/code&gt; folder into its root location, and your site is up and running. No PHP, Ruby, Go, Python, or any other server language or framework required. &lt;em&gt;There is no step three!&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Your content is contained within the most future-proof formats possible.&lt;/strong&gt; Markdown files are just plain text with minimal decoration. HTML is the most well-established and widely-supported data exchange format in history. JPEG images certainly aren’t going anywhere any time soon. It’s safe to say that (unless you build your site with a bunch of crazy client-side Javascript rendering such that nothing works until all your code runs) you’ll be able to load a web browser decades from now and your site &lt;em&gt;will just work&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Your content is automatically backed up in multiple contexts, consistently.&lt;/strong&gt; If all of your content is “silo’ed” in a single MySQL database somewhere on some WordPress host, and that host goes down or their backup gets corrupted, you’re toast. Years of work, gone. (And let’s not forget the fact that WordPress sites are prime targets of hacker attacks on a daily basis!) However, if your content lives within Git repositories that likely exist in multiple locations simultaneously, the likelihood you’ll completely lose your repo and all that data is &lt;em&gt;vanishingly small&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;the-future-is-static&quot;&gt;The Future is Static&lt;/h3&gt;

&lt;p&gt;A lot of web developers are using the term &lt;strong&gt;JAMstack&lt;/strong&gt; these days to describe static sites build with the latest generation of tools, because the word “static” got a bad rap back in the day when new “dynamic” tools such as MovableType or WordPress were taking over the world. But there’s nothing truly static about static sites built with tools such as Jekyll, Hugo, and many others.&lt;/p&gt;

&lt;p&gt;I can use extremely sophisticated build processes to create fantastic website designs with tons of interactivity, and I can log into admin interfaces and use WYSYWIG editors if I want to to to manage content and publish updates at the click of a button. Using Jekyll doesn’t mean you have to hand-code every blog post in raw HTML and “FTP” it somewhere like in the old days. We live in a new age where static site generators are not only slick and amazing, but are in fact paving the way for the future of modern web development.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Static is dead. Love live static!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So to sum it all up, if you want to create blogs and websites that will stand the test of time, that will still be readable ten, twenty, probably even fifty years from now, that will not get buried in a stack of hard drives somewhere or lost in some database black hole on the internet, then you need to try out Jekyll (or one of its competitors). I guarantee you: once you go JAMstack, you’ll never go back!&lt;/p&gt;

&lt;hr /&gt;

&lt;p class=&quot;post-footer-meta&quot;&gt;&lt;strong&gt;&lt;em&gt;INTERSECT&lt;/em&gt;&lt;/strong&gt;&lt;em&gt; is a Jekyll-powered open web blog published by Whitefusion. Find out more about us and what drives us in &lt;a href=&quot;/about&quot;&gt;About Us&lt;/a&gt;.&lt;/em&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;

&lt;fieldset&gt;
  &lt;form action=&quot;https://whitefusion.us10.list-manage.com/subscribe/post?u=e4c1c61da664f0e2aa1915c92&amp;amp;id=bb80b27885&quot; id=&quot;embedded-subscribe-form&quot; method=&quot;post&quot;&gt;
  &lt;h3&gt;Subscribe to Our Newsletter&lt;/h3&gt;

  &lt;p&gt;Are you a designer, developer, project manager, or founder? Do you care about the open web and protecting users' privacy and security? Are you a Ruby programmer? If you said Yes to any of those things, then this newsletter is for you.&lt;/p&gt;

  &lt;label for=&quot;subscribe-email&quot;&gt;Your Email Address:&lt;/label&gt;
  &lt;input id=&quot;subscribe-email&quot; name=&quot;EMAIL&quot; type=&quot;email&quot; /&gt;
  &lt;input name=&quot;form_dom_id&quot; value=&quot;embedded-subscribe-form&quot; type=&quot;hidden&quot; /&gt;

  &lt;span class=&quot;no-spam&quot;&gt;&lt;strong&gt;No spam, ever.&lt;/strong&gt; We&amp;rsquo;ll never share your email address and you can opt out at any time.&lt;/span&gt;

  &lt;div id=&quot;mce-responses&quot; class=&quot;clear&quot;&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-error-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-success-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;    &lt;!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups--&gt;
    &lt;div style=&quot;position: absolute; left: -5000px;&quot; aria-hidden=&quot;true&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;b_e4c1c61da664f0e2aa1915c92_bb80b27885&quot; tabindex=&quot;-1&quot; value=&quot;&quot; /&gt;&lt;/div&gt;

  &lt;input type=&quot;submit&quot; onclick=&quot;var _this = this;this.disabled=true; this.value='Sending...'; setTimeout(function() { _this.form.submit() }, 100)&quot; value=&quot;Subscribe&quot; /&gt;
  &lt;/form&gt;
&lt;/fieldset&gt;

</description>
        <pubDate>Thu, 19 Jul 2018 00:00:00 +0000</pubDate>
        <link>https://intersect.whitefusion.io/open-web/the-archival-benefits-of-static-site-generators</link>
        <guid isPermaLink="true">https://intersect.whitefusion.io/open-web/the-archival-benefits-of-static-site-generators</guid>
        
        
        <category>Open Web</category>
        
      </item>
    
      <item>
        <title>Jekyll’s Hidden Depths</title>
        <description>&lt;img src="https://intersect.whitefusion.io/assets/depths.jpg"&gt;&lt;h2&gt;As anyone who has used Jekyll for a while knows, it's capable of so much more than first meets the eye. Here are a few tricks I discovered while redesigning my personal website.&lt;/h2&gt;&lt;p&gt;As part of a large redesign of my personal website and blog at &lt;a href=&quot;https://jaredwhite.com&quot;&gt;jaredwhite.com&lt;/a&gt;, I was able to put Jekyll through its paces in some interesting ways. The following is a collection of three nifty Jekyll techniques you might not have heard about before. (At least I hadn’t…these all came about through copious trial and error. My pain is your gain!)&lt;/p&gt;

&lt;h3 id=&quot;organize-your-posts-folder&quot;&gt;Organize Your Posts Folder&lt;/h3&gt;

&lt;p&gt;The default way you add a new post to a Jekyll blog is to create a new file in the &lt;code class=&quot;highlighter-rouge&quot;&gt;_posts&lt;/code&gt; folder, typically with a date at the beginning such as &lt;code class=&quot;highlighter-rouge&quot;&gt;2018-05-13-a-blog-post.md&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But for my new website, I wanted to be able to distinguish between different post types. For example, I’ve organized my content around four types: &lt;strong&gt;Thoughts&lt;/strong&gt;, &lt;strong&gt;Pictures&lt;/strong&gt;, &lt;strong&gt;Links&lt;/strong&gt;, and &lt;strong&gt;Articles&lt;/strong&gt;. Having those all taking up space in a single folder would make it very hard to navigate over time. In addition, I have posts going back years (older blog content had been imported into Jekyll previously), so I wanted to avoid having a folder with many hundreds of files in it.&lt;/p&gt;

&lt;p&gt;So the first thing I did was create separate folders under &lt;code class=&quot;highlighter-rouge&quot;&gt;_posts&lt;/code&gt; for the four types. I ended up with:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;_posts/thoughts&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;_posts/pictures&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;_posts/links&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;_posts/articles&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The next step was to collect all content in a given year into a folder just for that year. The result was a series of descriptive folder hierarchies such as &lt;code class=&quot;highlighter-rouge&quot;&gt;_posts/pictures/2018&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;_posts/articles/2014&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now it’s important to remember that Jekyll doesn’t add any special metadata to posts in subfolders of &lt;code class=&quot;highlighter-rouge&quot;&gt;_posts&lt;/code&gt;. So just putting something in &lt;code class=&quot;highlighter-rouge&quot;&gt;pictures&lt;/code&gt; doesn’t ensure that post will go into the &lt;code class=&quot;highlighter-rouge&quot;&gt;pictures&lt;/code&gt; category. You still have to add &lt;code class=&quot;highlighter-rouge&quot;&gt;categories: pictures&lt;/code&gt; to the front matter of the post. &lt;em&gt;However&lt;/em&gt;, there is one mechanism to put posts into categories automatically: you can create a top-level folder inside your Jekyll repo and put a &lt;code class=&quot;highlighter-rouge&quot;&gt;_posts&lt;/code&gt; folder into &lt;em&gt;that&lt;/em&gt;. In other words, it would be something like &lt;code class=&quot;highlighter-rouge&quot;&gt;pictures/_posts&lt;/code&gt;, etc.&lt;/p&gt;

&lt;p&gt;I’ve done that sort of thing in the past and ended up not liking it. I really don’t like cluttering up my top-level Jekyll folder any more than I have to. I prefer the mental model of having everything organized inside of a single &lt;code class=&quot;highlighter-rouge&quot;&gt;_posts&lt;/code&gt; folder. So I’ve chosen the manual route as far as category front matter is concerned. (And to be honest, I’m using a custom Rails-based content editing system I’ve built for myself which populates the front matter for each content type automatically. So it’s pretty straightforward.)&lt;/p&gt;

&lt;p&gt;I definitely love having year subfolders for posts and will now start doing that on all my blogs in the future. Organizing hierarchically by some meaningful criteria such as category/post-type is a useful option for larger sites that might have hundreds or thousands of posts.&lt;/p&gt;

&lt;h3 id=&quot;format-post-types-with-includes&quot;&gt;Format Post Types with Includes&lt;/h3&gt;

&lt;p&gt;It’s common in Jekyll setups to have a &lt;code class=&quot;highlighter-rouge&quot;&gt;post.html&lt;/code&gt; layout file which renders a blog post and an &lt;code class=&quot;highlighter-rouge&quot;&gt;index.html&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;blog.html&lt;/code&gt; page which loops through blog posts and renders excerpts (or maybe the full post text).&lt;/p&gt;

&lt;p&gt;In the case of my new website, because of the “social media” styling that the content and visual design is oriented around, I knew that I’d want a &lt;strong&gt;Thought&lt;/strong&gt; post or &lt;strong&gt;Picture&lt;/strong&gt; post or &lt;strong&gt;Link&lt;/strong&gt; post to look the same everywhere—on the homepage, on a single post page, or in archives (such as hashtag pages…more on that below). The only exception is an &lt;strong&gt;Article&lt;/strong&gt; post. Those display as excerpts in all contexts except the actual post page, in which case the full article is rendered as long-form content.&lt;/p&gt;

&lt;p&gt;To make matters even more complicated, I also wanted to control how different post types would render out in RSS/JSON feeds. Not only that, I use Jekyll to build the HTML for my email newsletters (each newsletter is a compilation of the most recent posts on the site), so I would need to control how post types render for the special (aka goofy and weird) markup required for the email campaigns.&lt;/p&gt;

&lt;p&gt;So I decided to use &lt;em&gt;partials&lt;/em&gt; to define the markup for all my post types. Because of the various contexts mentioned above, I ended up with &lt;em&gt;three&lt;/em&gt; different folders under the &lt;code class=&quot;highlighter-rouge&quot;&gt;_includes&lt;/code&gt; folder:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;_includes/post_types&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;_includes/feed_post_types&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;_includes/newsletter_post_types&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And in each of those folders, I have four files:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;thought.html&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;picture.html&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;link.html&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;article.html&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then in various template files in various contexts, I’m able to include the relevant post type partials as required. For example, in my feed templates:&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;{% for post in site.posts limit:20 %}
  {% capture page_content %}
    {% if post.category == 'thoughts' %}
      {% include feed_post_types/thought.html post=post %}
    {% elsif post.category == 'pictures' %}
      {% include feed_post_types/picture.html post=post %}
    {% elsif post.category == 'links' %}
      {% include feed_post_types/link.html post=post %}
    {% else %}
      {% include feed_post_types/article.html post=post %}
    {% endif %}
  {% endcapture %}
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;item&amp;gt;&lt;/span&gt;
    ...
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;description&amp;gt;&lt;/span&gt;{{ page_content | xml_escape }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/description&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/item&amp;gt;&lt;/span&gt;
{% endfor %}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A common programming refrain is DRY (Don’t Repeat Yourself). Using partials to define post markup only once, and then including those in various contexts across the whole site is a great way to imbue your Jekyll build with DRY principles.&lt;/p&gt;

&lt;h3 id=&quot;jazz-up-your-posts-with-hashtags&quot;&gt;Jazz Up Your Posts with Hashtags&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;The following technique isn’t supported if you host your Jekyll blog with GitHub pages. I highly recommend using a hosting provider such as &lt;a href=&quot;https://www.netlify.com&quot;&gt;Netlify&lt;/a&gt; which allows you to use any custom plugin (and many other highly-advanced workflows) for your Jekyll deployments. Bonus: for the majority of smaller-scale projects, it’s free!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;One of the ways I make my website feel more like modern social media is the use of hashtags. If I post a picture of bridge in Portland, I want to be able to add &lt;strong&gt;#portland&lt;/strong&gt; as a hashtag in the caption. This requires two interrelated pieces of functionality to be in place: (a) the ability for the hashtag to link to an archive page with all similarly-tagged content, and (b) the ability for posts to be tagged in the first place.&lt;/p&gt;

&lt;p&gt;Tags as a concept for Jekyll posts is nothing new. &lt;a href=&quot;https://github.com/pattex/jekyll-tagging&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;jekyll-tagging&lt;/code&gt;&lt;/a&gt; is a popular gem and the one I used to solve (b). So for the front matter of a post that has one or more hashtags, it’s very simple to specify them like so:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;tags: Facebook openweb&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;jekyll-tagging&lt;/code&gt; plugin then handles creating an archive for the &lt;code class=&quot;highlighter-rouge&quot;&gt;Facebook&lt;/code&gt; tag, the &lt;code class=&quot;highlighter-rouge&quot;&gt;openweb&lt;/code&gt; tag, etc., and making sure the post ends up in those archives. &lt;em&gt;However&lt;/em&gt;, what it doesn’t do is convert the actual &lt;strong&gt;#Facebook&lt;/strong&gt; or &lt;strong&gt;#openweb&lt;/strong&gt; text to working links that point to those tag archives. To solve (a), I had to write my own custom plugin that would provide a special Liquid filter (&lt;code class=&quot;highlighter-rouge&quot;&gt;/_plugins/hashtags.rb&lt;/code&gt;):&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Jekyll&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;HashtagsFilter&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;hashtags&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;tag_url_prefix&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;vi&quot;&gt;@context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;registers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:site&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;url&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;to_s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;/tag/&quot;&lt;/span&gt;      
      &lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;gsub&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/(^|\s|\&amp;gt;)#([a-z\d-]+)/i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1&amp;lt;a href=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tag_url_prefix&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; class=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;hashtag&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;gt;#&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;2&amp;lt;/a&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;no&quot;&gt;Liquid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Template&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;register_filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Jekyll&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;HashtagsFilter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And that’s it! Now all I need to do is use the &lt;code class=&quot;highlighter-rouge&quot;&gt;hashtags&lt;/code&gt; filter wherever I display content that needs those special links. For example:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;{{ include.post.content | hashtags }}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It’s perhaps not ideal that you have to put a &lt;strong&gt;#hashtag&lt;/strong&gt; in the body of a post as well as include the tag in the front matter. But what follows is no surprise: my custom editing system actually scans a post’s content for hashtags and adds them to the front matter automatically. It’s pretty great.&lt;/p&gt;

&lt;h3 id=&quot;jekyll-you-can-run-but-you-cant-hyde&quot;&gt;Jekyll: You can run but you can’t Hyde&lt;/h3&gt;

&lt;p&gt;Jekyll is an amazingly powerful content system right out of the box. But with a few added plugins or creative uses of existing features, it can do almost anything imaginable. I’ve built a wide variety of websites on top of Jekyll over the last couple of years and I still feel like I’m learning new tricks every day.&lt;/p&gt;

&lt;p&gt;I hope you found this article helpful! Got any questions about Jekyll? &lt;a href=&quot;mailto:jared@jaredwhite.com&quot;&gt;Please direct them my way&lt;/a&gt; (plus sign up to get notified about future posts 😁⬇︎).&lt;/p&gt;

&lt;hr /&gt;

&lt;p class=&quot;post-footer-meta&quot;&gt;&lt;strong&gt;&lt;em&gt;INTERSECT&lt;/em&gt;&lt;/strong&gt;&lt;em&gt; is a Jekyll-powered open web blog published by Whitefusion. Find out more about us and what drives us in &lt;a href=&quot;/about&quot;&gt;About Us&lt;/a&gt;.&lt;/em&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;

&lt;fieldset&gt;
  &lt;form action=&quot;https://whitefusion.us10.list-manage.com/subscribe/post?u=e4c1c61da664f0e2aa1915c92&amp;amp;id=bb80b27885&quot; id=&quot;embedded-subscribe-form&quot; method=&quot;post&quot;&gt;
  &lt;h3&gt;Subscribe to Our Newsletter&lt;/h3&gt;

  &lt;p&gt;Are you a designer, developer, project manager, or founder? Do you care about the open web and protecting users' privacy and security? Are you a Ruby programmer? If you said Yes to any of those things, then this newsletter is for you.&lt;/p&gt;

  &lt;label for=&quot;subscribe-email&quot;&gt;Your Email Address:&lt;/label&gt;
  &lt;input id=&quot;subscribe-email&quot; name=&quot;EMAIL&quot; type=&quot;email&quot; /&gt;
  &lt;input name=&quot;form_dom_id&quot; value=&quot;embedded-subscribe-form&quot; type=&quot;hidden&quot; /&gt;

  &lt;span class=&quot;no-spam&quot;&gt;&lt;strong&gt;No spam, ever.&lt;/strong&gt; We&amp;rsquo;ll never share your email address and you can opt out at any time.&lt;/span&gt;

  &lt;div id=&quot;mce-responses&quot; class=&quot;clear&quot;&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-error-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-success-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;    &lt;!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups--&gt;
    &lt;div style=&quot;position: absolute; left: -5000px;&quot; aria-hidden=&quot;true&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;b_e4c1c61da664f0e2aa1915c92_bb80b27885&quot; tabindex=&quot;-1&quot; value=&quot;&quot; /&gt;&lt;/div&gt;

  &lt;input type=&quot;submit&quot; onclick=&quot;var _this = this;this.disabled=true; this.value='Sending...'; setTimeout(function() { _this.form.submit() }, 100)&quot; value=&quot;Subscribe&quot; /&gt;
  &lt;/form&gt;
&lt;/fieldset&gt;

</description>
        <pubDate>Wed, 09 May 2018 00:00:00 +0000</pubDate>
        <link>https://intersect.whitefusion.io/the-art-of-code/jekylls-hidden-depths</link>
        <guid isPermaLink="true">https://intersect.whitefusion.io/the-art-of-code/jekylls-hidden-depths</guid>
        
        
        <category>The Art of Code</category>
        
      </item>
    
      <item>
        <title>Why Service Objects are an Anti-Pattern</title>
        <description>&lt;img src="https://intersect.whitefusion.io/assets/software-patterns.jpg"&gt;&lt;h2&gt;Article after article has been published in recent years about the benefits of adding service objects to Rails applications. I’m here to tell you they’re wrong. There is a better way.&lt;/h2&gt;&lt;p&gt;I have been vocal from time to time in internet discussions regarding service objects and why I believe they are the wrong solution to a legitimate problem. In fact, not only do I think better solutions exist than service objects in the majority of cases, I maintain that service objects are an anti-pattern which indicates a troubling lack of regard for sound object-oriented design principles.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/what-if-i-told-you-adding-service-objects-doesnt-make-your-rails-codebase-any-better.jpg&quot; alt=&quot;What if I told you that adding service objects doesn't make your Rails codebase any better&quot; style=&quot;border: 2px solid #c00&quot; /&gt;&lt;/p&gt;

&lt;p&gt;It’s hard to get such lofty points across in a random tweet here or comment there. So I decided to write this article and dig into some real-world code that illustrates my position precisely.&lt;/p&gt;

&lt;p&gt;What do I mean when I use the term &lt;em&gt;anti-pattern&lt;/em&gt;? Here’s a reasonable description from StackOverflow:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Anti-patterns are certain patterns in software development that are considered bad programming practices. As opposed to design patterns which are common approaches to common problems which have been formalized and are generally considered a good development practice, anti-patterns are the opposite and are undesirable.&lt;/p&gt;

  &lt;p&gt;Source: &lt;a href=&quot;https://stackoverflow.com/a/980616&quot;&gt;https://stackoverflow.com/a/980616&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In order to demonstrate why I don’t like service objects, I’m going to look at some code I inherited from a past development team for a client project. I can’t go too much into context since this application is still in private beta, but let’s just say it’s a social platform where you can rate media (images or videos) and those ratings trigger certain callback-style actions such as updating algorithmic data and adding activities to various users’ timelines.&lt;/p&gt;

&lt;p&gt;We have a pretty simple data model where a &lt;code class=&quot;highlighter-rouge&quot;&gt;Rating&lt;/code&gt; object can be created in the database that &lt;code class=&quot;highlighter-rouge&quot;&gt;belongs_to&lt;/code&gt; both a &lt;code class=&quot;highlighter-rouge&quot;&gt;User&lt;/code&gt; object and a &lt;code class=&quot;highlighter-rouge&quot;&gt;Media&lt;/code&gt; object (all these examples are shortened from the production files):&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Rating&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Base&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;belongs_to&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:user&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;belongs_to&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:media&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Media&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Base&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;has_many&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:ratings&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;You get the idea. Now in order to handle an incoming rating from a user, the previous developer created a service object called &lt;code class=&quot;highlighter-rouge&quot;&gt;MediaRating&lt;/code&gt; which gets called from the controller:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MediaRating&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;mr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;MediaRating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;update_rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;initialize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;vi&quot;&gt;@user&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;update_rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;vi&quot;&gt;@user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ratings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;media: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;first&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nil?&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;# do create stuff&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;# do update stuff&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# do some extra stuff here like run algorithmic data processing,&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# add social activities to timelines, etc.&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And here’s the relevant controller code:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;media&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Media&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:media_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;to_i&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;MediaRating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Bear in mind that this code was originally written quite a while ago. These days, all the cool cats writing service objects have settled on a bit of formality in terms of the API presented, so if I were to rewrite this service object, I’d probably do something like this:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# add this to Gemfile:&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'smart_init'&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;UserMediaRater&lt;/span&gt;
  &lt;span class=&quot;kp&quot;&gt;extend&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;SmartInit&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;initialize_with&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:media&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:rating&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;is_callable&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;call&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;vi&quot;&gt;@user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ratings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;media: &lt;/span&gt;&lt;span class=&quot;vi&quot;&gt;@media&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;first&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# etc.&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# updated command from the controller:&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;UserMediaRater&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;problem-time&quot;&gt;Problem Time&lt;/h3&gt;

&lt;p&gt;Now this code doesn’t look so bad, right? It seems pretty clean and well-structured and easy to test. Well, the problem is that what you are seeing here is my polished up, greatly simplified version of this service object. The actual one in the codebase is 74 lines of spaghetti code with methods calling other methods which call other methods because the code to trigger algorithmic data processing and timeline updates and so forth is all shoehorned into this one service object. So actually, the flow is more like this:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Controller &amp;gt; Service Object &amp;gt; Rate Method &amp;gt; Update Rating &amp;gt; Some Other Update Method + (Run Algorithm &amp;gt; Refresh Related Data), then Invalidate Caches + Add Timeline Activities&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So every time I open up the codebase fresh and want to look at the block of code that simply creates or updates a rating of a media object by a user, I’m forced to wade through a bunch of ancillary functionality to get at the basic code path.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Well&lt;/em&gt;, you might say, &lt;em&gt;that developer obviously didn’t do a very good job writing the service object! They should have kept it simple and focused, and instead put additional processing code in other objects (maybe even other service objects!)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now wait a minute! The &lt;strong&gt;whole reason&lt;/strong&gt; we are told we need to extract code contained within standard Rails MVC patterns into service objects is because they help us break up complex code flows into standalone functions. But the problem is that there’s nothing to enforce that rule. &lt;em&gt;Nothing!&lt;/em&gt; You can write a simple service object, no doubt about it. But you can equally write a complex service object containing a bunch of methods that quickly turn into spaghetti code.&lt;/p&gt;

&lt;p&gt;What does this mean? It means &lt;strong&gt;the service object pattern has no intrinsic ability to make your codebase easier to read, easier to maintain, simpler, or exhibit  better separation of concerns&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If a pattern can foster nearly any sort of programming style with a nearly infinite spectrum of simple to highly complicated, then it ceases to be a useful pattern and describes nothing specific to developers.&lt;/p&gt;

&lt;h3 id=&quot;so-what-should-we-do-instead&quot;&gt;So What Should We Do Instead?&lt;/h3&gt;

&lt;p&gt;When I’m preparing to write a fair bit of code that I know will have to process incoming data and either create or update records along with other related functionality, I typically start by writing a class method on the most appropriate model. Now hold your horses, I’m not saying this is a superior pattern. I’m saying this is where I begin, &lt;em&gt;before&lt;/em&gt; I start looking for another pattern that might be a better fit.&lt;/p&gt;

&lt;p&gt;Let’s take a look what what it might look like if rating media were done using a class method on &lt;code class=&quot;highlighter-rouge&quot;&gt;Rating&lt;/code&gt; itself:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Rating&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Base&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;belongs_to&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:user&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;belongs_to&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:media&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;find_or_initialize_by&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;user: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;media: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rating&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;save&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# do some extra stuff here like run algorithmic data processing,&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# add social activities to timelines, etc.&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And the updated controller code:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;media&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Media&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:media_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;to_i&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;Rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now I’m already breathing a sigh of relief when I read this code, because putting the rating code directly in the &lt;code class=&quot;highlighter-rouge&quot;&gt;Rate&lt;/code&gt; model ensures that the functionality is closer to the data structures that are most impacted by the code.  Want to open up the codebase and find out how to rate something? Look in the &lt;code class=&quot;highlighter-rouge&quot;&gt;Rate&lt;/code&gt; model! It’s very straightforward.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;However&lt;/em&gt;…I’m ultimately still not happy with this code for one big reason. As a rule of thumb, I like to call instance methods and use Rails associations whenever possible. To me it’s code smell to sprinkle class methods all over the place and avoid using associations and standard OOP principles as intended.  In this case, it seems weird to me that I can’t do something along the lines of &lt;code class=&quot;highlighter-rouge&quot;&gt;@media.rate&lt;/code&gt; in the controller.  After all, I’m loading up a media object and I want to rate it. Why isn’t there a clear interface to do that?&lt;/p&gt;

&lt;h3 id=&quot;concerns-and-poros-are-your-friends&quot;&gt;Concerns and POROs are Your Friends&lt;/h3&gt;

&lt;p&gt;Once I’m convinced I need to start moving complex code out of a model class method, I’m going to want to find a better pattern than just stuffing a bunch of bits into various models’ instance methods. After all, the problems that come with fat models is why people recommend breaking code out into service objects in the first place!&lt;/p&gt;

&lt;p&gt;But in reality, the downsides of fat models isn’t so much that you have a single object with a lot of methods, it’s that those methods (and presumably related unit tests) are all jumbled together in one file. What you really need is a way to keep bits of key functionality separated out from other bits of key functionality in terms of code comprehension, and then you need some sort of rule of thumb for which bits of code really should be relocated into separate objects altogether.&lt;/p&gt;

&lt;p&gt;Let’s take a look at what we could do with this media rating business. First, I’m going to extract the chunk of code we’ve been wrestling with into a concern (which is just a slightly enhanced Rails version of the standard Ruby mixin). Let’s call this concern &lt;code class=&quot;highlighter-rouge&quot;&gt;Ratable&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Ratable&lt;/span&gt;
  &lt;span class=&quot;kp&quot;&gt;extend&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActiveSupport&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Concern&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;included&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;has_many&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:ratings&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;create_or_update_user_rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ratings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;find_or_initialize_by&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;user: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rating&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;save&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# do some extra stuff here like run algorithmic data processing,&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# add social activities to timelines, etc.&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;Media&lt;/code&gt; class now benefits as well, as we can take that &lt;code class=&quot;highlighter-rouge&quot;&gt;has_many :ratings&lt;/code&gt; directive out and keep that contained within the new concern:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Media&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Base&lt;/span&gt;
  &lt;span class=&quot;kp&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Ratable&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And the updated controller code:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;to_i&lt;/span&gt;
&lt;span class=&quot;no&quot;&gt;Media&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:media_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;create_or_update_user_rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;ss&quot;&gt;user: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;ss&quot;&gt;rating: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ah, this is already feeling much better. All I have to do in the controller is find the media object and call a single instance method that’s clearly named as to what it does. It’s a friendly interface that feels Rails-y in the best possible way.&lt;/p&gt;

&lt;p&gt;There’s still a problem though. This &lt;code class=&quot;highlighter-rouge&quot;&gt;create_or_update_user_rating&lt;/code&gt; method is trying to do way too much. It makes sense to handle the database access here, but the algorithmic data processing and timeline updates seem like actions that should be triggered to happen after the fact and defined someplace else.&lt;/p&gt;

&lt;p&gt;The standard Rails way would be to put this code into ActiveRecord callbacks. Now I have no problem with callbacks, and I’ll gladly use them if it feels like a reasonable fit. But in this case, the two main things that need to happen seem like totally unrelated bits of functionality that are only tangentially related to the particular media, rating, and user objects involved.&lt;/p&gt;

&lt;p&gt;So let’s use this opportunity to do some proper domain modeling and move that extra functionality out of the concern and into other POROs. We’ll keep our &lt;code class=&quot;highlighter-rouge&quot;&gt;create_or_update_user_rating&lt;/code&gt; method nice and simple by pointing to those new objects:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;create_or_update_user_rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ratings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;find_or_initialize_by&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;user: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rating&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rating&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;save&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# Let's extract out additional functionality to POROs or relevant models.&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# Better yet, encapsulate these into background jobs?&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# Left as an exercise for the reader...&lt;/span&gt;
    &lt;span class=&quot;no&quot;&gt;Rating&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Processor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;no&quot;&gt;Timeline&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Activities&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;add_for_rating&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;rating_record&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now before you start to get twitchy there, &lt;code class=&quot;highlighter-rouge&quot;&gt;Rating::Processor&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;Timeline::Activites&lt;/code&gt; aren’t more “service objects.” These are POROs (Plain Old Ruby Objects) that are modeled using carefully considered OOP paradigms. One object is what I call a “processor” pattern: it takes input, crunches some numbers, and then saves the output somewhere. The other is a collection pattern that manages adding and removing items and the consequence of those actions. Nothing fancy or original here, but that’s the point.&lt;/p&gt;

&lt;p&gt;We could have attempted to use the service object pattern here instead, perhaps by refactoring &lt;code class=&quot;highlighter-rouge&quot;&gt;UserMediaRater&lt;/code&gt; to call additional services objects such as &lt;code class=&quot;highlighter-rouge&quot;&gt;ProcessNewRating&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;AddTimelineActivityForRating&lt;/code&gt;. But how is that any more readable or any more well-structured than using concerns and POROs? Instead of succumbing to a huge &lt;code class=&quot;highlighter-rouge&quot;&gt;app/services&lt;/code&gt; folder filled with what are essentially functions, we can engage instead in real domain modeling to come up with class names, data structures, and object methods that are designed for readability and ease of use.&lt;/p&gt;

&lt;p&gt;And that’s my final point: &lt;strong&gt;using concerns and POROs instead of service objects encourages better interfaces, proper separation of concerns, sound use of OOP principles, and easier code comprehension.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I’m out of time to talk about testing strategies, but if you’re worried that using concerns or more advanced POROs will cause additional problems with your tests as compared with service objects, here are a couple of useful resources:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://youtu.be/5hN6OZDyQtk&quot;&gt;On Writing Software Well—Video by David Heinemeier Hansson&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.honeybadger.io/poro-plain-old-ruby-object-tests-and-specs/&quot;&gt;Speed up Rails tests 10x by using PORO domain models&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There’s a lot more I could talk about regarding how model or controller-level Rails concerns combined with useful PORO patterns is a better fit than service objects in the vast majority of cases, so keep an eye out for future articles in this vein.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; service objects are crappy and better solutions exist most of the time. Please use those instead. Thank you!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Send your thoughtful, rage-free responses to &lt;a href=&quot;https://twitter.com/jaredcwhite&quot;&gt;@jaredcwhite&lt;/a&gt;&lt;/em&gt; 😊&lt;/p&gt;

&lt;hr /&gt;

&lt;p class=&quot;post-footer-meta&quot;&gt;&lt;strong&gt;&lt;em&gt;INTERSECT&lt;/em&gt;&lt;/strong&gt;&lt;em&gt; is a Jekyll-powered open web blog published by Whitefusion. Find out more about us and what drives us in &lt;a href=&quot;/about&quot;&gt;About Us&lt;/a&gt;.&lt;/em&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;

&lt;fieldset&gt;
  &lt;form action=&quot;https://whitefusion.us10.list-manage.com/subscribe/post?u=e4c1c61da664f0e2aa1915c92&amp;amp;id=bb80b27885&quot; id=&quot;embedded-subscribe-form&quot; method=&quot;post&quot;&gt;
  &lt;h3&gt;Subscribe to Our Newsletter&lt;/h3&gt;

  &lt;p&gt;Are you a designer, developer, project manager, or founder? Do you care about the open web and protecting users' privacy and security? Are you a Ruby programmer? If you said Yes to any of those things, then this newsletter is for you.&lt;/p&gt;

  &lt;label for=&quot;subscribe-email&quot;&gt;Your Email Address:&lt;/label&gt;
  &lt;input id=&quot;subscribe-email&quot; name=&quot;EMAIL&quot; type=&quot;email&quot; /&gt;
  &lt;input name=&quot;form_dom_id&quot; value=&quot;embedded-subscribe-form&quot; type=&quot;hidden&quot; /&gt;

  &lt;span class=&quot;no-spam&quot;&gt;&lt;strong&gt;No spam, ever.&lt;/strong&gt; We&amp;rsquo;ll never share your email address and you can opt out at any time.&lt;/span&gt;

  &lt;div id=&quot;mce-responses&quot; class=&quot;clear&quot;&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-error-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-success-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;    &lt;!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups--&gt;
    &lt;div style=&quot;position: absolute; left: -5000px;&quot; aria-hidden=&quot;true&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;b_e4c1c61da664f0e2aa1915c92_bb80b27885&quot; tabindex=&quot;-1&quot; value=&quot;&quot; /&gt;&lt;/div&gt;

  &lt;input type=&quot;submit&quot; onclick=&quot;var _this = this;this.disabled=true; this.value='Sending...'; setTimeout(function() { _this.form.submit() }, 100)&quot; value=&quot;Subscribe&quot; /&gt;
  &lt;/form&gt;
&lt;/fieldset&gt;

</description>
        <pubDate>Tue, 06 Mar 2018 00:00:00 +0000</pubDate>
        <link>https://intersect.whitefusion.io/the-art-of-code/why-service-objects-are-an-anti-pattern</link>
        <guid isPermaLink="true">https://intersect.whitefusion.io/the-art-of-code/why-service-objects-are-an-anti-pattern</guid>
        
        
        <category>The Art of Code</category>
        
      </item>
    
      <item>
        <title>Use Ruby Objects to Keep Your Rake Tasks Clean</title>
        <description>&lt;h2&gt;In the spirit of DHH's On Writing Software Well series, I'll be demonstrating by looking at live production code.&lt;/h2&gt;&lt;p&gt;I’ve been inspired by David Heinemeier Hansson’s &lt;a href=&quot;https://www.youtube.com/playlist?list=PL9wALaIpe0Py6E_oHCgTrD6FvFETwJLlx&quot;&gt;new YouTube series &lt;em&gt;On Writing Software Well&lt;/em&gt;&lt;/a&gt;, because I think it’s positively delightful when somebody takes the time and care to walk through real-world, production code and discuss why things were done the way they were and the tradeoffs involved, as well as the possibilities for improving that code further.&lt;/p&gt;

&lt;p&gt;Today, I want to talk about how to keep ancillary pieces of your infrastructure fairly clean and minimalist. In terms of Rails, one place I’ve seen where it’s easy to end up with “bags of code” that aren’t really structured or straightforward to test are Rake tasks.&lt;/p&gt;

&lt;p&gt;Let’s look at a Rake task I recently refactored on a client project. We were  using Heroku’s new Review Apps functionality, which allows every pull request on GitHub to spawn a new application. QA specialists or product managers are then able to look at that particular feature branch’s functionality in isolation, which is a good thing. However, the post-deploy rake task we had in place to make sure we were setting up the proper subdomains, SSL certificates, indexing data for search, etc., was getting increasingly unwieldy. It was just a big “bag of code,” and that to me was a sign some refactoring was sorely needed.&lt;/p&gt;

&lt;p&gt;Let’s take a look at the &lt;em&gt;before&lt;/em&gt; code (a few bits of private data have been changed to protect the innocent):&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:heroku&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;desc&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Run as the postdeploy script in heroku&quot;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:setup&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ENV&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'HEROKU_APP_NAME'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;new_domain&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;ENV&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'HEROKU_APP_NAME'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.domain.com&quot;&lt;/span&gt;

      &lt;span class=&quot;c1&quot;&gt;# set up Heroku domain (or use existing one on a redeploy)&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;heroku_domains&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;heroku&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;domain_info&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;heroku_domains&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'hostname'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;new_domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;domain_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nil?&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;domain_info&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;heroku&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;hostname: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new_domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

      &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ENV&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'CLOUDFLARE_API_KEY'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;email&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ENV&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'CLOUDFLARE_API_EMAIL'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;connection&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Cloudflare&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;key: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;email: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;email&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;zone&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;connection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zones&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;find_by_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;domain.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

      &lt;span class=&quot;c1&quot;&gt;# delete old dns records&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;zone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dns_records&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;record&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;new_domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dns_record&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;dns_record&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;delete&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

      &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;zone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dns_records&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
        &lt;span class=&quot;ss&quot;&gt;type: &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;CNAME&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;ss&quot;&gt;name: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new_domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;ss&quot;&gt;content: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;domain_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'cname'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
        &lt;span class=&quot;ss&quot;&gt;ttl: &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;240&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;ss&quot;&gt;proxied: &lt;/span&gt;&lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;to_json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;content_type: &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'application/json'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

      &lt;span class=&quot;c1&quot;&gt;# install SSL cert&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;s3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;AWS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;S3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;new&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;bucket&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;buckets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'theres_a_hole_in_the_bucket'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;crt_data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bucket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;objects&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'__domain_com.crt'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;key_data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bucket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;objects&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'__domain_com.key'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;heroku&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ssl_endpoint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;heroku&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ssl_endpoint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;certificate_chain: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;crt_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;private_key: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

      &lt;span class=&quot;n&quot;&gt;sh&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;rake heroku:start_indexing&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;s2&quot;&gt;&quot;** ERROR IN HEROKU RAKE **&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;inspect&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;backtrace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;ensure&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;heroku&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;update&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;maintenance: &lt;/span&gt;&lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Postdeploy script complete&quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;heroku&lt;/span&gt;
    &lt;span class=&quot;vi&quot;&gt;@heroku&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;PlatformAPI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;connect_oauth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;ENV&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'HEROKU_PLATFORM_KEY'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Whew! That’s a lot to wade through. Not only is the task getting pretty long at this point, there are certain dependencies between the blocks of code being executed that are difficult to ascertain just by a cursory examination.&lt;/p&gt;

&lt;p&gt;Now let’s look at how I refactored this. First, I created a new class in the &lt;code class=&quot;highlighter-rouge&quot;&gt;lib&lt;/code&gt; folder called &lt;code class=&quot;highlighter-rouge&quot;&gt;HerokuReviewAppPostDeploy&lt;/code&gt; and extracted each block into a separate method. You’ll notice we are actually doing even more in this new object, such as connecting to the GitHub repository and getting the branch name of the pull request so we can put a Jira ticket number right in the review app’s subdomain. That requirement turned up right as I was in the middle of refactoring, so I was thankful I avoided an even larger bag of code!&lt;/p&gt;

&lt;p&gt;Here’s the full class:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HerokuReviewAppPostDeploy&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;attr_accessor&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:heroku_api&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;initialize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;heroku_app_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;heroku_api&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;PlatformAPI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;connect_oauth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;ENV&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'HEROKU_PLATFORM_KEY'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;turn_on_maintenance_mode&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;heroku_api&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;update&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;maintenance: &lt;/span&gt;&lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;turn_off_maintenance_mode&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;heroku_api&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;update&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;maintenance: &lt;/span&gt;&lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;determine_subdomain&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;new_subdomain&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;pull_request_number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;match&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/pr-([0-9]+)/&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;NoMethodError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;unless&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pull_request_number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nil?&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;github_info&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;HTTParty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'https://api.github.com/repos/organization/reponame/pulls/'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pull_request_number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;basic_auth: &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;username: &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'janedoe'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;password: &lt;/span&gt;&lt;span class=&quot;no&quot;&gt;ENV&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;GITHUB_API_KEY&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]}).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;parsed_response&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;github_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;head&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;branch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;github_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;head&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;ref&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;jira_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;branch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;match&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/WXYZ-([0-9]+)/&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;NoMethodError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;unless&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jira_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nil?&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;new_subdomain&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;match&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/^([a-z]+)/&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;-wxyz-&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;jira_id&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;new_subdomain&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;determine_domain&lt;/span&gt;
    &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;determine_subdomain&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.domain.com&quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;setup_domain_on_heroku&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new_domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# set up Heroku domain (or use existing one on a redeploy)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;heroku_domains&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;heroku_api&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;domain_info&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;heroku_domains&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'hostname'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;new_domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;domain_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nil?&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;heroku_api&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;hostname: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new_domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;domain_info&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;setup_domain_on_cloudflare&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new_domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;heroku_domain_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ENV&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'CLOUDFLARE_API_KEY'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;email&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ENV&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'CLOUDFLARE_API_EMAIL'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;connection&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Cloudflare&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;key: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;email: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;email&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;zone&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;connection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;zones&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;find_by_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;domain.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;zone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dns_records&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;record&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;new_domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dns_record&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;dns_record&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;delete&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;zone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dns_records&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
      &lt;span class=&quot;ss&quot;&gt;type: &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;CNAME&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;ss&quot;&gt;name: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new_domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;ss&quot;&gt;content: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heroku_domain_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'cname'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
      &lt;span class=&quot;ss&quot;&gt;ttl: &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;240&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;ss&quot;&gt;proxied: &lt;/span&gt;&lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;to_json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;content_type: &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'application/json'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;setup_ssl_cert_on_heroku&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# install SSL cert&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;s3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;AWS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;S3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;new&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;bucket&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;buckets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'theres_a_hole_in_the_bucket'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;crt_data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bucket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;objects&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'__domain_com.crt'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;key_data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bucket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;objects&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'__domain_com.key'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;read&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;heroku_api&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ssl_endpoint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;heroku_api&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ssl_endpoint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;certificate_chain: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;crt_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;private_key: &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Not only does this new approach allow us to use an object to break out bits of functionality into single-purpose methods, but because certain methods require data generated by other methods, we can include those variables as method arguments (for example, passing &lt;code class=&quot;highlighter-rouge&quot;&gt;new_domain&lt;/code&gt; explicitly into &lt;code class=&quot;highlighter-rouge&quot;&gt;setup_domain_on_heroku&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;So how does our Rake task look now? Much, much better:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:heroku&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;desc&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Run as the postdeploy script in heroku&quot;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:setup&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ENV&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'HEROKU_APP_NAME'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;post_deploy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;HerokuReviewAppPostDeploy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heroku_app_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;post_deploy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;turn_on_maintenance_mode&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;new_domain&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;post_deploy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;determine_domain&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;heroku_domain_info&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;post_deploy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setup_domain_on_heroku&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new_domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;post_deploy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setup_domain_on_cloudflare&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new_domain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;heroku_domain_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;post_deploy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setup_ssl_cert_on_heroku&lt;/span&gt;
      &lt;span class=&quot;no&quot;&gt;Rake&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'db:migrate'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;invoke&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;sh&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;rake heroku:start_indexing&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;s2&quot;&gt;&quot;** ERROR IN HEROKU RAKE **&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;inspect&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;backtrace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;ensure&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;post_deploy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;turn_off_maintenance_mode&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Postdeploy script complete&quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It’s way easier to see the individual steps needed to go through the process of completing the review app setup, and through the use of setting a variable returned from one method and passing it along to another, the data dependencies between the steps are now clear. In addition, because &lt;code class=&quot;highlighter-rouge&quot;&gt;HerokuReviewAppPostDeploy&lt;/code&gt; uses straightforward method names that describe exactly what’s going on, the explanatory need for code comments is greatly reduced.&lt;/p&gt;

&lt;p&gt;You can use this &lt;strong&gt;extract-into-a-standalone-object&lt;/strong&gt; technique for other “bag of code” areas of your application. Background jobs are another good example. I prefer to keep my Sidekiq workers very minimalist…a lot of the time I make sure they call a single method on a single model and that’s all.&lt;/p&gt;

&lt;p&gt;I hope this was helpful in giving you some new ideas on how to improve your own codebase, based on live production code. Stay tuned for the next article in this series. (Subscribe to the &lt;strong&gt;INTERSECT&lt;/strong&gt; newsletter below so you don’t miss it!)&lt;/p&gt;

&lt;hr /&gt;

&lt;p class=&quot;post-footer-meta&quot;&gt;&lt;strong&gt;&lt;em&gt;INTERSECT&lt;/em&gt;&lt;/strong&gt;&lt;em&gt; is a Jekyll-powered open web blog published by Whitefusion. Find out more about us and what drives us in &lt;a href=&quot;/about&quot;&gt;About Us&lt;/a&gt;.&lt;/em&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;

&lt;fieldset&gt;
  &lt;form action=&quot;https://whitefusion.us10.list-manage.com/subscribe/post?u=e4c1c61da664f0e2aa1915c92&amp;amp;id=bb80b27885&quot; id=&quot;embedded-subscribe-form&quot; method=&quot;post&quot;&gt;
  &lt;h3&gt;Subscribe to Our Newsletter&lt;/h3&gt;

  &lt;p&gt;Are you a designer, developer, project manager, or founder? Do you care about the open web and protecting users' privacy and security? Are you a Ruby programmer? If you said Yes to any of those things, then this newsletter is for you.&lt;/p&gt;

  &lt;label for=&quot;subscribe-email&quot;&gt;Your Email Address:&lt;/label&gt;
  &lt;input id=&quot;subscribe-email&quot; name=&quot;EMAIL&quot; type=&quot;email&quot; /&gt;
  &lt;input name=&quot;form_dom_id&quot; value=&quot;embedded-subscribe-form&quot; type=&quot;hidden&quot; /&gt;

  &lt;span class=&quot;no-spam&quot;&gt;&lt;strong&gt;No spam, ever.&lt;/strong&gt; We&amp;rsquo;ll never share your email address and you can opt out at any time.&lt;/span&gt;

  &lt;div id=&quot;mce-responses&quot; class=&quot;clear&quot;&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-error-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-success-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;    &lt;!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups--&gt;
    &lt;div style=&quot;position: absolute; left: -5000px;&quot; aria-hidden=&quot;true&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;b_e4c1c61da664f0e2aa1915c92_bb80b27885&quot; tabindex=&quot;-1&quot; value=&quot;&quot; /&gt;&lt;/div&gt;

  &lt;input type=&quot;submit&quot; onclick=&quot;var _this = this;this.disabled=true; this.value='Sending...'; setTimeout(function() { _this.form.submit() }, 100)&quot; value=&quot;Subscribe&quot; /&gt;
  &lt;/form&gt;
&lt;/fieldset&gt;

</description>
        <pubDate>Fri, 02 Mar 2018 00:00:00 +0000</pubDate>
        <link>https://intersect.whitefusion.io/the-art-of-code/use-real-objects-to-keep-your-rake-tasks-and-workers-clean</link>
        <guid isPermaLink="true">https://intersect.whitefusion.io/the-art-of-code/use-real-objects-to-keep-your-rake-tasks-and-workers-clean</guid>
        
        
        <category>The Art of Code</category>
        
      </item>
    
      <item>
        <title>Farewell Facebook! Goodbye Google! Why I Rage Quit Javascript Trackers</title>
        <description>&lt;img src="https://intersect.whitefusion.io/assets/spycameras.jpg"&gt;&lt;h2&gt;I'd had enough. As a fierce advocate of the open web, I couldn't live with myself until I took action.&lt;/h2&gt;&lt;p&gt;I’d had enough.&lt;/p&gt;

&lt;p&gt;I couldn’t live with myself until I took action.&lt;/p&gt;

&lt;p&gt;So I rage quit all my Javascript trackers.&lt;/p&gt;

&lt;p&gt;In a single, solitary act, I &lt;strong&gt;removed&lt;/strong&gt; all Facebook and Google trackers (including Google Analytics) from all of my blogs and online publications. Yes, even &lt;strong&gt;INTERSECT&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Since I don’t &lt;em&gt;require&lt;/em&gt; detailed stats to give to advertisers or marketing gurus, the only reason to track anything is simply vanity. Sure, I’d love to know if you, dear reader, are another number on the chart for this URL.&lt;/p&gt;

&lt;p&gt;But do I really need to know if 10 people or 1,000 people read this article? No. It’s much more important to me to see that someone has signed up for an email newsletter or has contacted me directly with a comment or inquiry. Those are the metrics that matter. Pageviews, for the most part, are entirely irrelevant (other than to provide statistical data for said marketing gurus to optimize some sort of sales funnel).&lt;/p&gt;

&lt;p&gt;However, the question of the usefulness of pageview stats isn’t why I removed the trackers. I did so because &lt;a href=&quot;https://intersect.whitefusion.io/privacy-and-security/why-duckduckgo-is-a-harbinger-of-a-better-internet&quot;&gt;I am sick of handing yet more data over to giant Silicon Valley corporations and have written about the perils of doing so&lt;/a&gt;. Injecting a Facebook script just so somebody can click a Like button on my website isn’t worth it anymore. Injecting a Google script just so I can see that 3 people from Kalamazoo read an article I wrote two months ago isn’t worth it anymore.&lt;/p&gt;

&lt;p&gt;It’s entirely possible I’ll change my mind down the road and decide I do want to collect some subset of traffic data, perhaps to help me see which topics are more popular or if a particular page is doing well in search engines. But if that becomes a necessity, I will either install an open-source analytics engine on a server under my direct control where I can verify that user data is secure and protected, or I will build my own analytics engine. (Being a programmer has its perks. 😊)&lt;/p&gt;

&lt;p&gt;As a fierce advocate of the open web, I believe we (the collective web developer community) need to take a principled stand to Just Say No to the invasive and dangerous proliferation of Javascript trackers. It’s absurd and ridiculous that if I simply go to a webpage to read a review of the Apple HomePod, I’ll see that my browser’s blocker extension had to protect me against 31 different third-party analytics and ad serving scripts.&lt;/p&gt;

&lt;p&gt;Look, I’m not against ads per se. If you want to display sponsorship information on your website to show who’s footing the bill for that content I’m reading, go for it. But you don’t need 57 varieties of script injects on your page to do that. There’s always a better way.&lt;/p&gt;

&lt;p&gt;I rage quit all my Javascript trackers. Maybe you can delete a few too.&lt;/p&gt;

&lt;hr /&gt;

&lt;p class=&quot;post-footer-meta&quot;&gt;&lt;strong&gt;&lt;em&gt;INTERSECT&lt;/em&gt;&lt;/strong&gt;&lt;em&gt; is a Jekyll-powered open web blog published by Whitefusion. Find out more about us and what drives us in &lt;a href=&quot;/about&quot;&gt;About Us&lt;/a&gt;.&lt;/em&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;

&lt;fieldset&gt;
  &lt;form action=&quot;https://whitefusion.us10.list-manage.com/subscribe/post?u=e4c1c61da664f0e2aa1915c92&amp;amp;id=bb80b27885&quot; id=&quot;embedded-subscribe-form&quot; method=&quot;post&quot;&gt;
  &lt;h3&gt;Subscribe to Our Newsletter&lt;/h3&gt;

  &lt;p&gt;Are you a designer, developer, project manager, or founder? Do you care about the open web and protecting users' privacy and security? Are you a Ruby programmer? If you said Yes to any of those things, then this newsletter is for you.&lt;/p&gt;

  &lt;label for=&quot;subscribe-email&quot;&gt;Your Email Address:&lt;/label&gt;
  &lt;input id=&quot;subscribe-email&quot; name=&quot;EMAIL&quot; type=&quot;email&quot; /&gt;
  &lt;input name=&quot;form_dom_id&quot; value=&quot;embedded-subscribe-form&quot; type=&quot;hidden&quot; /&gt;

  &lt;span class=&quot;no-spam&quot;&gt;&lt;strong&gt;No spam, ever.&lt;/strong&gt; We&amp;rsquo;ll never share your email address and you can opt out at any time.&lt;/span&gt;

  &lt;div id=&quot;mce-responses&quot; class=&quot;clear&quot;&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-error-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-success-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;    &lt;!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups--&gt;
    &lt;div style=&quot;position: absolute; left: -5000px;&quot; aria-hidden=&quot;true&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;b_e4c1c61da664f0e2aa1915c92_bb80b27885&quot; tabindex=&quot;-1&quot; value=&quot;&quot; /&gt;&lt;/div&gt;

  &lt;input type=&quot;submit&quot; onclick=&quot;var _this = this;this.disabled=true; this.value='Sending...'; setTimeout(function() { _this.form.submit() }, 100)&quot; value=&quot;Subscribe&quot; /&gt;
  &lt;/form&gt;
&lt;/fieldset&gt;

</description>
        <pubDate>Fri, 16 Feb 2018 00:00:00 +0000</pubDate>
        <link>https://intersect.whitefusion.io/privacy-and-security/farewell-facebook-goodbye-google</link>
        <guid isPermaLink="true">https://intersect.whitefusion.io/privacy-and-security/farewell-facebook-goodbye-google</guid>
        
        
        <category>Privacy and Security</category>
        
      </item>
    
      <item>
        <title>Why DuckDuckGo is a Harbinger of a Better Internet</title>
        <description>&lt;img src="https://intersect.whitefusion.io/assets/duckduckgo.jpg"&gt;&lt;h2&gt;It's time to draw a line in the sand. Some companies fight to protect user privacy and security online. Others don't. We need to hold the latter group accountable.&lt;/h2&gt;&lt;p&gt;Gabriel Weinberg, CEO of DuckDuckGo, &lt;a href=&quot;https://ca.finance.yahoo.com/news/google-facebook-watching-every-move-163800243.html&quot;&gt;claims that Google and Facebook are the biggest threats&lt;/a&gt; to your &lt;a href=&quot;https://www.msn.com/en-us/money/other/duckduckgo-ceo-dont-wait-for-zuckerberg-to-save-your-data/vi-AAv1Iwt&quot;&gt;privacy and security online&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You would be justified in thinking Weinberg has a vested interest in trashing his top competitor (Google) and is doing whatever he can to get his David vs. Goliath message out there. But the fact remains: he’s right.&lt;/p&gt;

&lt;p&gt;Google has far outstripped its motto of “Don’t Be Evil” and is spreading its invasive tracker technology across the entire internet. Go to almost any website these days and choose &lt;em&gt;View Source&lt;/em&gt; in your browser. Scroll through the code and you’ll see tons of Google-sourced tracking code and script injections. Same for Facebook code as well–after all, the &lt;em&gt;only&lt;/em&gt; reason Facebook is a large profitable business is because they have a enormous data trove on every user and can utilize that data for hyper-targeted advertiser campaigns.&lt;/p&gt;

&lt;p&gt;The reason DuckDuckGo plays a crucial role in wresting our control away from Google (and to a lesser extent Facebook) is due to its very public and committed stance to protect users’ privacy. While DuckDuckGo does show ads in its search engine, those ads are entirely related to specific search terms in the current query and do not rely on user tracking on its site or on other sites. In addition, DuckDuckGo derives revenue from affiliate links (for instance when you click on a link that goes to Amazon or some other online retailer). And this year, DuckDuckGo has released additional browser software and extensions that help block tracking scripts, force secure HTTPS access on all websites, and provide tools to beef up your online privacy.&lt;/p&gt;

&lt;p&gt;Is Google in immediate danger of being usurped by DuckDuckGo? Frankly, no. Google still has an order-of-magnitude more market share than any other search engine (Bing being the distant runner-up). &lt;a href=&quot;https://duckduckgo.com/traffic&quot;&gt;But as this graph clearly shows, DuckDuckGo is growing at an exponential rate&lt;/a&gt;, and if that trend continues, at some point Google will have something rather substantial to worry about.&lt;/p&gt;

&lt;p&gt;A better internet that serves its users well long into the future requires a deliberate, principled commitment to protect the privacy and security of the online community. We need more internet companies to think like DuckDuckGo.&lt;/p&gt;

&lt;hr /&gt;

&lt;p class=&quot;post-footer-meta&quot;&gt;&lt;strong&gt;&lt;em&gt;INTERSECT&lt;/em&gt;&lt;/strong&gt;&lt;em&gt; is a Jekyll-powered open web blog published by Whitefusion. Find out more about us and what drives us in &lt;a href=&quot;/about&quot;&gt;About Us&lt;/a&gt;.&lt;/em&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;

&lt;fieldset&gt;
  &lt;form action=&quot;https://whitefusion.us10.list-manage.com/subscribe/post?u=e4c1c61da664f0e2aa1915c92&amp;amp;id=bb80b27885&quot; id=&quot;embedded-subscribe-form&quot; method=&quot;post&quot;&gt;
  &lt;h3&gt;Subscribe to Our Newsletter&lt;/h3&gt;

  &lt;p&gt;Are you a designer, developer, project manager, or founder? Do you care about the open web and protecting users' privacy and security? Are you a Ruby programmer? If you said Yes to any of those things, then this newsletter is for you.&lt;/p&gt;

  &lt;label for=&quot;subscribe-email&quot;&gt;Your Email Address:&lt;/label&gt;
  &lt;input id=&quot;subscribe-email&quot; name=&quot;EMAIL&quot; type=&quot;email&quot; /&gt;
  &lt;input name=&quot;form_dom_id&quot; value=&quot;embedded-subscribe-form&quot; type=&quot;hidden&quot; /&gt;

  &lt;span class=&quot;no-spam&quot;&gt;&lt;strong&gt;No spam, ever.&lt;/strong&gt; We&amp;rsquo;ll never share your email address and you can opt out at any time.&lt;/span&gt;

  &lt;div id=&quot;mce-responses&quot; class=&quot;clear&quot;&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-error-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-success-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;    &lt;!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups--&gt;
    &lt;div style=&quot;position: absolute; left: -5000px;&quot; aria-hidden=&quot;true&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;b_e4c1c61da664f0e2aa1915c92_bb80b27885&quot; tabindex=&quot;-1&quot; value=&quot;&quot; /&gt;&lt;/div&gt;

  &lt;input type=&quot;submit&quot; onclick=&quot;var _this = this;this.disabled=true; this.value='Sending...'; setTimeout(function() { _this.form.submit() }, 100)&quot; value=&quot;Subscribe&quot; /&gt;
  &lt;/form&gt;
&lt;/fieldset&gt;

</description>
        <pubDate>Mon, 12 Feb 2018 00:00:00 +0000</pubDate>
        <link>https://intersect.whitefusion.io/privacy-and-security/why-duckduckgo-is-a-harbinger-of-a-better-internet</link>
        <guid isPermaLink="true">https://intersect.whitefusion.io/privacy-and-security/why-duckduckgo-is-a-harbinger-of-a-better-internet</guid>
        
        
        <category>Privacy and Security</category>
        
      </item>
    
      <item>
        <title>Swift for Javascript and Ruby Developers</title>
        <description>&lt;p&gt;Last week I had the privilege of presenting on the topic of learning Swift from the perspective of a developer currently familiar with Ruby or Javascript. I showed off some of the reasons why Swift is a pretty exciting language for those used to working with lightweight scripting languages, and I also demonstrated some example code that highlights similar functionality implementations across all three languages.&lt;/p&gt;

&lt;p&gt;You can see the &lt;a href=&quot;http://slides.com/jaredwhite/swift&quot;&gt;presentation slides here&lt;/a&gt;, and &lt;a href=&quot;https://github.com/whitefusionhq/swift-for-ruby-and-js-devs&quot;&gt;code examples are available on Github&lt;/a&gt;. If you yourself are a developer in one or more of these languages and have suggestions for further code examples or useful comparisons, please submit a pull request on Github and let me know!&lt;/p&gt;

</description>
        <pubDate>Mon, 14 Nov 2016 00:00:00 +0000</pubDate>
        <link>https://intersect.whitefusion.io/the-art-of-code/swift-for-ruby-and-javascript-developers</link>
        <guid isPermaLink="true">https://intersect.whitefusion.io/the-art-of-code/swift-for-ruby-and-javascript-developers</guid>
        
        
        <category>The Art of Code</category>
        
      </item>
    
      <item>
        <title>Minimum Viable Product Backlog</title>
        <description>&lt;img src="https://intersect.whitefusion.io/assets/mvpb.jpg"&gt;&lt;h2&gt;You will have many, many ideas for your startup product during your initial development cycle. Here's why you should resist the temptation to add them to your product backlog.&lt;/h2&gt;&lt;p&gt;Part of the exercise in defining a Minimum Viable Product (MVP) is being strict about maintaining a Minimum Viable Product Backlog (MVPB). As a founder or designer working in a new startup, it’s oh-so-easy to add yet &lt;em&gt;another&lt;/em&gt; story to the backlog (or icebox if you want a more precise term) every time you have an idea for a new feature or business strategy. I’ve unfortunately worked on projects that had man-years worth of crud built up in their agile/scrum tool, with enough work to feed a team of developers far beyond any sane requirements for a real MVP.&lt;/p&gt;

&lt;p&gt;One of those projects was my own.&lt;/p&gt;

&lt;p&gt;Yes, I admit it…I can still load up Trello boards chock-full of all kinds of off-the-cuff ideas from when I was working on a startup product several years ago. Did most of those ideas help me move closer to a successful MVP? Are any of those ideas relevant today? For the most part, no. Yet I exerted so much time and energy inserting all those ideas into the system, time and energy that would have been better spent talking to and listening to potential customers of my product, or building the basic essence of what I already knew I was attempting to achieve.&lt;/p&gt;

&lt;p&gt;Listen, I’m not saying it’s bad to have ideas. If you wake up at 3am with an &lt;em&gt;Aha!&lt;/em&gt; rumbling about in your sleep-deprived brain, then by all means jot it down. But jot it down in your notebook/diary, not your scrum tool. If it ends up really feeling like a valid idea after you’ve had time to reflect, you will have plenty of opportunity to come up with success metrics with which validate it and a plan to execute it—&lt;em&gt;before&lt;/em&gt; it ends up lurking near the edges of the kanban board like a swamp creature.&lt;/p&gt;

&lt;p&gt;I am currently working on a &lt;em&gt;new&lt;/em&gt; startup product, and this time I am intentionally keeping my backlog as short and concise as possible. Every day that I add some new code or UI for a feature, I ask myself, is this a Minimum Viable Product yet? Is this ready to test with real users? How soon can I show this to people and collect &lt;em&gt;their&lt;/em&gt; ideas and feedback?&lt;/p&gt;

&lt;p&gt;Unless you are an epic Jobsian-level genius (newsflash: you’re not), you are probably going to have one or two really great ideas, a handful of decent ideas, and truckload of truly terrible ideas during any given product development cycle. The sooner you allow others to provide the yardstick as to which of your ideas falls into those various camps, the better.&lt;/p&gt;

&lt;p&gt;And for Pete’s sake, clean up that damn backlog!&lt;/p&gt;

&lt;hr /&gt;

&lt;p class=&quot;post-footer-meta&quot;&gt;&lt;strong&gt;&lt;em&gt;INTERSECT&lt;/em&gt;&lt;/strong&gt;&lt;em&gt; is a Jekyll-powered open web blog published by Whitefusion. Find out more about us and what drives us in &lt;a href=&quot;/about&quot;&gt;About Us&lt;/a&gt;.&lt;/em&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;

&lt;fieldset&gt;
  &lt;form action=&quot;https://whitefusion.us10.list-manage.com/subscribe/post?u=e4c1c61da664f0e2aa1915c92&amp;amp;id=bb80b27885&quot; id=&quot;embedded-subscribe-form&quot; method=&quot;post&quot;&gt;
  &lt;h3&gt;Subscribe to Our Newsletter&lt;/h3&gt;

  &lt;p&gt;Are you a designer, developer, project manager, or founder? Do you care about the open web and protecting users' privacy and security? Are you a Ruby programmer? If you said Yes to any of those things, then this newsletter is for you.&lt;/p&gt;

  &lt;label for=&quot;subscribe-email&quot;&gt;Your Email Address:&lt;/label&gt;
  &lt;input id=&quot;subscribe-email&quot; name=&quot;EMAIL&quot; type=&quot;email&quot; /&gt;
  &lt;input name=&quot;form_dom_id&quot; value=&quot;embedded-subscribe-form&quot; type=&quot;hidden&quot; /&gt;

  &lt;span class=&quot;no-spam&quot;&gt;&lt;strong&gt;No spam, ever.&lt;/strong&gt; We&amp;rsquo;ll never share your email address and you can opt out at any time.&lt;/span&gt;

  &lt;div id=&quot;mce-responses&quot; class=&quot;clear&quot;&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-error-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-success-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;    &lt;!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups--&gt;
    &lt;div style=&quot;position: absolute; left: -5000px;&quot; aria-hidden=&quot;true&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;b_e4c1c61da664f0e2aa1915c92_bb80b27885&quot; tabindex=&quot;-1&quot; value=&quot;&quot; /&gt;&lt;/div&gt;

  &lt;input type=&quot;submit&quot; onclick=&quot;var _this = this;this.disabled=true; this.value='Sending...'; setTimeout(function() { _this.form.submit() }, 100)&quot; value=&quot;Subscribe&quot; /&gt;
  &lt;/form&gt;
&lt;/fieldset&gt;

</description>
        <pubDate>Fri, 29 Apr 2016 00:00:00 +0000</pubDate>
        <link>https://intersect.whitefusion.io/product-management/minimum-viable-product-backlog</link>
        <guid isPermaLink="true">https://intersect.whitefusion.io/product-management/minimum-viable-product-backlog</guid>
        
        
        <category>Product Management</category>
        
      </item>
    
      <item>
        <title>Goodbye Medium, Hello Jekyll</title>
        <description>&lt;img src="https://intersect.whitefusion.io/assets/hello-jekyll.jpg"&gt;&lt;h2&gt;Every few years, we're told that we need to abandon self-hosted blogs and join a proprietary network. And every few years, we eventually discover that we got hoodwinked. Here's my journey back into the light.&lt;/h2&gt;&lt;p&gt;In the early days of blogging, such activity was seen as the latest Internet offensive against the professional gatekeepers and old-school publishers of old. &lt;em&gt;Bloggers unite!&lt;/em&gt; While it’s true that some bloggers used hosted, Software-as-a-Service platforms, as opposed to self-hosted, open source platforms such as Wordpress—in most cases blogs were clearly websites under the author’s direct control and often presented content via the author’s own design preferences. Even the most network-ish blogging platform in vogue only a few years ago, Tumblr, allowed for a custom design and domain name so that you barely could even tell some blogs were actually on Tumblr.&lt;/p&gt;

&lt;p&gt;Yet for a while now, self-hosted/self-published blogs have been under attack. The first wave of the attack was powered by Facebook. We were told we didn’t need blogs anymore. Just create a Facebook Page and publish everything there! Put Facebook’s massive network effect to good use and avoid the complexity of having to maintain your own website.&lt;/p&gt;

&lt;p&gt;Then reality began to creep in. Events such as Facebook tweaking their news feed algorithm dramatically to bury Facebook Page content unless you paid to have it “boosted” left a sour feeling in a lot of content marketers’ mouths. In addition, a number of well-respected content authors within a very short amount of time seemed to be shouting in unison that a much older publishing outlet was suddenly the new hotness again: &lt;strong&gt;email!&lt;/strong&gt; Yes, that’s right, the lowly email newsletter was undergoing a sort of renaissance, and it simply didn’t make sense to promote an email newsletter if you didn’t also publish content on your own website under your direct control.&lt;/p&gt;

&lt;h3 id=&quot;enter-medium&quot;&gt;Enter Medium&lt;/h3&gt;

&lt;p&gt;Medium started with a very simple premise: the rise of social media (and particularly Twitter) threatened the cultivation and propagation of long-form, journalistic, quality publishing. There needed to be a snazzy new content network with a bias towards rewarding good content and punishing or eliminating “bad” content (aka clickbait, content farm garbage, etc.).&lt;/p&gt;

&lt;p&gt;Now I want to state here on the outset that I have a great deal of respect for Medium as both a product and a company. I think they accomplished what they set out to do, and in the process moved the bar forward both in terms of content presentation (their minimalist style has had a big influence on blog design across the web) and content authoring (their in-page editor is pretty slick and now much copied in other platforms).&lt;/p&gt;

&lt;p&gt;However, Medium has always had an awkward and uncomfortable relationship with the open web. In one sense, Medium benefits from the open web and in fact wouldn’t be possible without it. While there’s certainly a Medium mobile app, and Medium launched making use of Twitter’s network effect, I think it’s safe to say that a great deal of Medium’s traffic has come from web-based avenues (not to mention Medium’s editing tool up until recently was &lt;em&gt;only&lt;/em&gt; available on the web).&lt;/p&gt;

&lt;p&gt;On the other hand, Medium threatens the open web because it essentially replaces it. Instead of blogging on your own website, you blog on Medium either as an individual or within a publication. Instead of discovering content through web searches or links from other blogs/forums/etc., you discover content through Medium’s own content-surfacing features. Instead of following people through a variety of different social networks, email newsletters, bookmarks, forums, RSS, etc., you follow people using Medium’s own social network.&lt;/p&gt;

&lt;p&gt;While it’s true that you can use your own domain for Medium publications (and that’s exactly what we did with the first version of &lt;strong&gt;INTERSECT&lt;/strong&gt;), it’s pretty clear that it’s a Medium publication using Medium’s own design and marketing feature-set. Even your ability to email a newsletter to followers of your Medium publication is very tightly-controlled within Medium’s purview.&lt;/p&gt;

&lt;h3 id=&quot;the-false-promise-of-medium&quot;&gt;The False Promise of Medium&lt;/h3&gt;

&lt;p&gt;So why, pray tell, would any content author abandon publishing on their own website and publish instead on a proprietary network such as Medium? The answer is &lt;strong&gt;eyeballs&lt;/strong&gt;. The promise of Medium is that the “best content” surfaces, bubbling up to the top and into everyone’s feeds, and you get way more traffic than you could with your own website. A recent such move by Basecamp—migrating their popular blog Signal v. Noise onto Medium—trumpets this phenomenon.&lt;/p&gt;

&lt;p&gt;There’s only one problem with this scenario: it’s &lt;em&gt;false&lt;/em&gt;. Medium is not immune from the negative aspects of network effects, and in fact seems strangely reluctant to tackle them. What I mean is that, as the network grows, more and more of the content that bubbles up to the top comes from an increasingly small number of top content publishers, and the gargantuan “long tail” of niche publishers and content by unknown authors gets completely buried. In other words, if you &lt;em&gt;already&lt;/em&gt; have a large network and are well known, you may do quite well on Medium, but if you’re starting relatively from scratch, Medium will get you nowhere.&lt;/p&gt;

&lt;p&gt;It’s kind of like the “top charts” on music stores, app download stores, etc. The very few things that actually make it onto the charts do incredibly well, but if you’re not one of the lucky ones to be featured in a chart or specially curated by the platform’s editorial team, you’re toast.&lt;/p&gt;

&lt;p&gt;How do I know all this? Because, for me, Medium turned out to be a total bust.&lt;/p&gt;

&lt;h3 id=&quot;articles-with-no-traffic&quot;&gt;Articles With No Traffic&lt;/h3&gt;

&lt;p&gt;I’ve always been accustomed to getting a certain measure of traffic to anything I write online, even if it’s only a handful of people. Through a variety of channels, somehow on my worst day I still see some activity. I’ve been publishing online since the 90’s (blogging before blogs were blogs!), so I’m no stranger to the ups and downs of the web content world.&lt;/p&gt;

&lt;p&gt;Which is why I was flabbergasted to see, over time, that a number of the articles I posted on Medium got absolutely no traffic. That’s right, I’m talking &lt;strong&gt;zero&lt;/strong&gt; readers. And even articles that did get some traffic never took off in the way you’d expect. I maybe got a few hundred reads but the vast majority of that audience came from outside of Medium—another forum, or social network, etc. Which begs the question: why publish content on Medium if the traffic you get isn’t intrinsic to Medium? If Medium boasts its own major network effect, I certainly never saw it.&lt;/p&gt;

&lt;p&gt;However, when Medium recently rolled out new publication features such as email newsletters and custom domains, I decided to give it one last try. I’d been wanting to start a new online blog/magazine as part of a broad content marketing initiative at my company &lt;a href=&quot;https://whitefusion.io&quot;&gt;Whitefusion&lt;/a&gt;, and Medium’s tools made that an easy proposition. Thus the first version of &lt;strong&gt;INTERSECT&lt;/strong&gt; was born.&lt;/p&gt;

&lt;p&gt;And again, I saw exactly what I had seen previously with articles published under my personal profile. No traffic, or traffic that was virtually all coming from outside of Medium’s network. &lt;em&gt;Sigh…&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;enter-jekyll&quot;&gt;Enter Jekyll&lt;/h3&gt;

&lt;p&gt;A few years ago, after a string of bad experiences developing websites for clients using Wordpress, I decided to abandon Wordpress entirely and use something else as a blogging platform. I went through a number of different options (and for a while created and used my own startup’s publishing platform). When the Ghost platform arose out of a successful Kickstarter campaign a couple of years ago, I gave that a try. But I never really found something that wholly clicked with me. Every solution, including my own startup’s, seemed compromised in one way or another.&lt;/p&gt;

&lt;p&gt;And then I discovered &lt;a href=&quot;http://jekyllrb.com&quot;&gt;Jekyll&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I feel rather stupid in hindsight that I didn’t jump on the bandwagon much sooner. Jekyll is a static site generator that was first released a few years ago by one of the founders of GitHub, and in fact Jekyll powers the site hosting features on GitHub used by many open source software projects. So it’s not exactly “new”. Furthermore, Jekyll is a Ruby application and uses technologies such as the Liquid template engine—all things I am professionally familiar with and love. All I can say is, my programmer’s bias towards dynamic, database-driven solutions must have left me confused about why static site generators were interesting or useful, and thus I didn’t pay it much heed.&lt;/p&gt;

&lt;p&gt;But due to setting up an &lt;a href=&quot;https://github.com/polished-rb/knockout-rb&quot;&gt;open source project on GitHub&lt;/a&gt; of my own last year, I finally started to play around with and learn Jekyll. And that’s when my eyes were opened: Jekyll represents the very best of what the open web can provide to publishers, and in fact Jekyll offers concrete solutions to some of the issues that drive people to proprietary networks like Medium in the first place.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Performance.&lt;/strong&gt; Nobody wants their blog to die under the weight of an influx of massive traffic. If you publish an article on Medium that suddenly gets millions of views, no worry. But if your little blog on a shared host somewhere or a single VPS suddenly gets millions of views, &lt;em&gt;yikes!&lt;/em&gt; With Jekyll, that’s no longer an issue. Since the site is a static site (meaning that all the pages get generated once as regular HTML/CSS/JS/etc. files), you simply put it on a CDN (Content Delivery Network) and you now have the same performance characteristics that major content providers such as Netflix enjoy. No need to worry about caching your dynamic database-driven content because an entire Jekyll-generated site is essentially just one big cache!&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Security.&lt;/strong&gt; Nobody wants to deal with yet another Wordpress hack or Linux security breach or what-have-you just to put some content on the web. I don’t want to sit down in the morning to write and deal with &lt;code class=&quot;highlighter-rouge&quot;&gt;&quot;YOU GOT P0WNED!&quot;&lt;/code&gt; staring me in the face. Again, because a Jekyll-generated site has no database or server code to deal with, it’s about as secure as you could imagine. I suppose, in theory, someone could hack into Amazon’s CloudFront CDN and change an HTML file’s contents, but that wouldn’t get them anywhere because a CDN by definition is a distributed network of edge points all distributing the same cached content, which is easily refreshed at any time by the origin. A Jekyll blog is essentially a hack-proof blog.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Backups and Versioning.&lt;/strong&gt; Because a Jekyll website/blog is typically managed using a version control system such as Git, you automatically get versioning and backups as a core feature of the platform. This website, for example, is stored in a Git repository at &lt;a href=&quot;http://bitbucket.org&quot;&gt;Bitbucket&lt;/a&gt;, as well as a Git repository on my local computer. So if Bitbucket exploded tomorrow (or, more likely, my computer), no harm done. And every, I mean &lt;em&gt;every&lt;/em&gt; change to the website is logged. If a single word on one post is changed, that’s a new commit in the repository. If a color in the CSS stylesheet is changed, that’s a new commit in the repository. Even if a hacker somehow got access to my repository on Bitbucket and committed changes to the site, I could easily log in and rollback to a previous commit. And even if they somehow blew away the entire repository with all its version history, guess what? I still have a clone of that repository on my local machine I can simply push back up to the cloud. &lt;em&gt;Booyeah!&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Markdown &amp;amp; Authoring Speed.&lt;/strong&gt; Now it’s true that out-of-the-box Jekyll is hard to use for a non-technical person, because it requires managing developer-focused software on your local computer and fiddling with text files. And yet…the flip-side is it’s incredibly fast to author and publish new content. This very article, for example, is a simple Markdown file I authored. All I have to do is commit this file to my local Git repository using &lt;a href=&quot;https://www.sourcetreeapp.com&quot;&gt;SourceTree&lt;/a&gt; and push that commit up to Bitbucket, and &lt;strong&gt;boom!&lt;/strong&gt; My article is published online. (How? I use &lt;a href=&quot;https://www.netlify.com&quot;&gt;Netlify&lt;/a&gt; which is a hosting company that auto-compiles Jekyll source files in your Git repository and distributes the generated site to a dedicated CDN.) Frankly, I find this authoring process more satisfying than dealing with funky WYSIWYG editors in some online CMS somewhere. In past times I’ve actually written in Markdown locally, and then copy-pasted generated HTML from the file into the HTML text field of an online CMS editor. Bad! Jekyll supports native Markdown (or HTML if you really prefer that) right out of the gate.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, having your own website powered by Jekyll + a CDN is actually far &lt;em&gt;more&lt;/em&gt; capable than a Medium publication because you can do whatever the hell you want with it. Want a signup form for your own email newsletter? No problem. Want blog comments linked to a web forum under your own control that fosters your own online community? No problem. Want lead-gen landing pages on your site? No problem. Want your own fonts, colors, layout, and design aesthetic? No problem.&lt;/p&gt;

&lt;p&gt;The only thing you don’t get is the Medium network effect. But, guess what? You can &lt;em&gt;still&lt;/em&gt; cross-post articles on Medium. Yes, the funny thing about Medium is they don’t forbid (and in fact encourage) reposting articles on Medium that you’ve already posted on your own site, and in fact those posts show up with a link at the bottom saying &lt;em&gt;Originally published at (link)&lt;/em&gt;. Your own website still gets all the link juice from Google, but you also get whatever network effect you might get on Medium. Best of both worlds???&lt;/p&gt;

&lt;h3 id=&quot;jekyll-forever&quot;&gt;Jekyll Forever!&lt;/h3&gt;

&lt;p&gt;As for me, whether or not I personally ever post on Medium again, I can say with certainty that I am never again getting hoodwinked by a proprietary publishing network. I fully believe in the mind-blowing awesomeness of the open web, where content is published on individual websites that are controlled fully by the authors of said content, and I am now 100% a convert to the wonderful capabilities of static site generation. If some day in the future I am no longer using Jekyll, I will be using whatever technology has evolved out of Jekyll, and that gets me pretty excited. As both a writer and a programmer, words are important to me. Words have great worth and need to be cared for and valued. Jekyll and its surrounding technological ecosystem make me feel like the words I write are being honored, and—at the end of the day—my happiness as a writer is what it’s all about.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;em&gt;Are you a writer or a publisher? Do you need help setting up a blazing-fast Jekyll-powered website or blog for your important content needs? &lt;a href=&quot;mailto:jared@jaredwhite.com&quot;&gt;Contact me today&lt;/a&gt; and let’s get this done.&lt;/em&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p class=&quot;post-footer-meta&quot;&gt;&lt;strong&gt;&lt;em&gt;INTERSECT&lt;/em&gt;&lt;/strong&gt;&lt;em&gt; is a Jekyll-powered open web blog published by Whitefusion. Find out more about us and what drives us in &lt;a href=&quot;/about&quot;&gt;About Us&lt;/a&gt;.&lt;/em&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;

&lt;fieldset&gt;
  &lt;form action=&quot;https://whitefusion.us10.list-manage.com/subscribe/post?u=e4c1c61da664f0e2aa1915c92&amp;amp;id=bb80b27885&quot; id=&quot;embedded-subscribe-form&quot; method=&quot;post&quot;&gt;
  &lt;h3&gt;Subscribe to Our Newsletter&lt;/h3&gt;

  &lt;p&gt;Are you a designer, developer, project manager, or founder? Do you care about the open web and protecting users' privacy and security? Are you a Ruby programmer? If you said Yes to any of those things, then this newsletter is for you.&lt;/p&gt;

  &lt;label for=&quot;subscribe-email&quot;&gt;Your Email Address:&lt;/label&gt;
  &lt;input id=&quot;subscribe-email&quot; name=&quot;EMAIL&quot; type=&quot;email&quot; /&gt;
  &lt;input name=&quot;form_dom_id&quot; value=&quot;embedded-subscribe-form&quot; type=&quot;hidden&quot; /&gt;

  &lt;span class=&quot;no-spam&quot;&gt;&lt;strong&gt;No spam, ever.&lt;/strong&gt; We&amp;rsquo;ll never share your email address and you can opt out at any time.&lt;/span&gt;

  &lt;div id=&quot;mce-responses&quot; class=&quot;clear&quot;&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-error-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-success-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;    &lt;!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups--&gt;
    &lt;div style=&quot;position: absolute; left: -5000px;&quot; aria-hidden=&quot;true&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;b_e4c1c61da664f0e2aa1915c92_bb80b27885&quot; tabindex=&quot;-1&quot; value=&quot;&quot; /&gt;&lt;/div&gt;

  &lt;input type=&quot;submit&quot; onclick=&quot;var _this = this;this.disabled=true; this.value='Sending...'; setTimeout(function() { _this.form.submit() }, 100)&quot; value=&quot;Subscribe&quot; /&gt;
  &lt;/form&gt;
&lt;/fieldset&gt;

</description>
        <pubDate>Wed, 30 Mar 2016 00:00:00 +0000</pubDate>
        <link>https://intersect.whitefusion.io/open-web/goodbye-medium-hello-jekyll</link>
        <guid isPermaLink="true">https://intersect.whitefusion.io/open-web/goodbye-medium-hello-jekyll</guid>
        
        
        <category>Open Web</category>
        
      </item>
    
      <item>
        <title>Don’t Fear the Dead Ends</title>
        <description>&lt;p&gt;I hate wasting time. I hate that feeling that the thing I’m spending lots, and lots, and lots of time and energy on might bring me absolutely no results.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt;: Job hunting (&lt;em&gt;so many resumes sent and so little response!&lt;/em&gt;). A side project that goes nowhere fast. Budgeting when your expenses exceed your income (&lt;em&gt;no matter how many times you rejigger your spreadsheet, the total is still minus!&lt;/em&gt;). Talking to potential cofounders, clients, customers, or creatives—and then…silence.&lt;/p&gt;

&lt;p&gt;There are dead ends in innovation as well. We hear all the time about people who kept trying to invent, kept trying to push the state of the art forward, and kept seeing their efforts come to naught. How many times did Edison attempt to construct a working lightbulb?&lt;/p&gt;

&lt;hr/&gt;

&lt;blockquote class=&quot;centered&quot;&gt;&lt;p&gt;It’s kind of fun to do the impossible. –Walt Disney&lt;/p&gt;&lt;/blockquote&gt;

&lt;hr/&gt;

&lt;p&gt;I’ve had to change my thinking. I still don’t like wasting time, but I’m more at peace with the idea of hustle, experimentation, and, in the words of Guy Kawasaki, “let a hundred flowers blossom.”&lt;/p&gt;

&lt;p&gt;Creating great product ideas, pursuing excellence in UX, and fostering passionate communities of users is not something you can just will into existence. It takes patience, courage, and just a little bit of insanity. Yes, doing the same thing over and over and over again and expecting a different result…&lt;em class=&quot;markup--em markup--p-em&quot;&gt;the last 49 iterations of this screen just didn’t work for anybody. Let’s go for 50!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Try new things. Write about different topics. Play in different markets. Build different kinds of businesses. Chase different types of customers. Engage in different styles of work environment. Create different varieties of product.&lt;/p&gt;&lt;p&gt;Some experiments will work. Others will fail. But instead of seeing every failure, every dead end as a setback, see them as opportunites.&lt;/p&gt;

&lt;p&gt;I’m starting to build up a habit where every time I see a dead end in my pursuit of something more, I tell myself &lt;em&gt;it’s not a setback, it’s an opportunity! &lt;/em&gt;That client ran out of money and dropped you from the project? &lt;strong&gt;Opportunity!&lt;/strong&gt; That product didn’t find market fit in time and now you have to pull the plug? &lt;strong&gt;Opportunity!&lt;/strong&gt; That blog you’ve been publishing for over two years just isn’t getting much traffic? &lt;strong&gt;Opportunity!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It’s feels crazy, I know, to think that way sometimes. Especially when you feel awful about letting other people down (or yourself down!) and when you’re simply trying to figure out how to make payroll, or pay your rent, or eat another meal. Life has a funny way of closing in on us until our brains are processing everything on a minute-level timescale. Yet, if you can force yourself to “zoom out” and start thinking in year-level timescales (or longer!), you will begin to see how your goals, values, and priorities have the power to reshape the landscape of your daily life and make room for opportunities (and even setbacks) to reap real and lasting rewards.&lt;/p&gt;

&lt;hr /&gt;

&lt;blockquote class=&quot;centered&quot;&gt;&lt;p&gt;Success is the ability to go from failure to failure without losing your enthusiasm.&lt;/p&gt;&lt;/blockquote&gt;

&lt;hr /&gt;

&lt;p class=&quot;post-footer-meta&quot;&gt;&lt;strong&gt;&lt;em&gt;INTERSECT&lt;/em&gt;&lt;/strong&gt;&lt;em&gt; is a Jekyll-powered open web blog published by Whitefusion. Find out more about us and what drives us in &lt;a href=&quot;/about&quot;&gt;About Us&lt;/a&gt;.&lt;/em&gt;&lt;br/&gt;&amp;nbsp;&lt;/p&gt;

&lt;fieldset&gt;
  &lt;form action='https://whitefusion.us10.list-manage.com/subscribe/post?u=e4c1c61da664f0e2aa1915c92&amp;amp;id=bb80b27885' id='embedded-subscribe-form' method='post'&gt;
  &lt;h3&gt;Subscribe to Our Newsletter&lt;/h3&gt;

  &lt;p&gt;Are you a designer, developer, project manager, or founder? Do you care about the open web and protecting users' privacy and security? Are you a Ruby programmer? If you said Yes to any of those things, then this newsletter is for you.&lt;/p&gt;

  &lt;label for='subscribe-email'&gt;Your Email Address:&lt;/label&gt;
  &lt;input id='subscribe-email' name='EMAIL' type='email' /&gt;
  &lt;input name='form_dom_id' value='embedded-subscribe-form' type='hidden' /&gt;

  &lt;span class=&quot;no-spam&quot;&gt;&lt;strong&gt;No spam, ever.&lt;/strong&gt; We&amp;rsquo;ll never share your email address and you can opt out at any time.&lt;/span&gt;

  &lt;div id=&quot;mce-responses&quot; class=&quot;clear&quot;&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-error-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
		&lt;div class=&quot;response&quot; id=&quot;mce-success-response&quot; style=&quot;display:none&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;    &lt;!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups--&gt;
    &lt;div style=&quot;position: absolute; left: -5000px;&quot; aria-hidden=&quot;true&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;b_e4c1c61da664f0e2aa1915c92_bb80b27885&quot; tabindex=&quot;-1&quot; value=&quot;&quot;&gt;&lt;/div&gt;

  &lt;input type='submit' onclick=&quot;var _this = this;this.disabled=true; this.value='Sending...'; setTimeout(function() { _this.form.submit() }, 100)&quot; value='Subscribe'/&gt;
  &lt;/form&gt;
&lt;/fieldset&gt;


</description>
        <pubDate>Thu, 28 Jan 2016 00:00:00 +0000</pubDate>
        <link>https://intersect.whitefusion.io/don-t-fear-the-dead-ends-5a49d7ab840d</link>
        <guid isPermaLink="true">https://intersect.whitefusion.io/don-t-fear-the-dead-ends-5a49d7ab840d</guid>
        
        
        <category>Growth</category>
        
      </item>
    
  </channel>
</rss>
