<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Noah Summers</title>
    <description>The latest articles on DEV Community by Noah Summers (@noahsummers).</description>
    <link>https://dev.to/noahsummers</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F229277%2Fd71d2765-362c-4e32-b968-d80a65b7524c.jpg</url>
      <title>DEV Community: Noah Summers</title>
      <link>https://dev.to/noahsummers</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/noahsummers"/>
    <language>en</language>
    <item>
      <title>Defining Class and Module Aliases in Ruby and Rails</title>
      <dc:creator>Noah Summers</dc:creator>
      <pubDate>Wed, 15 Apr 2020 11:55:13 +0000</pubDate>
      <link>https://dev.to/noahsummers/defining-class-and-module-aliases-in-ruby-and-rails-4a59</link>
      <guid>https://dev.to/noahsummers/defining-class-and-module-aliases-in-ruby-and-rails-4a59</guid>
      <description>&lt;p&gt;In Ruby, creating a new name for an existing value is easy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 1
b = a

b #=&amp;gt; 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Since Ruby module names are just constants (and classes are just special modules), you can treat them the same way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class OriginalName
end

NewName = OriginalName

NewName.new #=&amp;gt; #&amp;lt;OriginalName:0x00007ffdb0a59190&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In a Rails application, constants are expected to be defined in a file with a corresponding path and name (otherwise, the auto-loader will have trouble finding it).&lt;/p&gt;

&lt;p&gt;For example, the following model&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Nested::OriginalName &amp;lt; ApplicationRecord
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;would conventionally be defined in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app/models/nested/original_name.rb
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The alias, &lt;code&gt;Nested::NewName&lt;/code&gt;, would ideally be defined in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app/models/nested/new_name.rb
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Nested::NewName = Nested::OriginalName
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It's more likely, though, that you would be looking for a shorter alias, without the namespace. As long as you follow the file path and name conventions, you can safely define any alias you want:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# app/models/new_name.rb

NewName = Nested::OriginalName
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>ruby</category>
      <category>rails</category>
      <category>refactoring</category>
    </item>
    <item>
      <title>Deploying a Hugo Site with Git Submodules on AWS Amplify</title>
      <dc:creator>Noah Summers</dc:creator>
      <pubDate>Wed, 25 Mar 2020 12:34:55 +0000</pubDate>
      <link>https://dev.to/noahsummers/deploying-a-hugo-site-with-git-submodules-on-aws-amplify-50i5</link>
      <guid>https://dev.to/noahsummers/deploying-a-hugo-site-with-git-submodules-on-aws-amplify-50i5</guid>
      <description>&lt;p&gt;In the course of deploying my site to AWS Amplify, I ran into a few hiccups, attributable to both my project configuration and to the behavior of Hugo itself.&lt;/p&gt;

&lt;p&gt;After completing the simple setup process, Amplify ran the initial deployment and showed green check marks across the board, but the site was "unreachable" when I opened the URL.&lt;/p&gt;

&lt;p&gt;The default build configuration contains a single command: "hugo".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# amplify.yml

version: 0.1
frontend:
  phases:
    build:
      commands:
        - hugo
  artifacts:
    baseDirectory: public
    files:
      - '**/*'
  cache:
    paths: []
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I tried reproducing the problem locally, by following the same steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Clone the repo.&lt;/li&gt;
&lt;li&gt;Change to the project directory.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;hugo&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This revealed the problem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WARN 2020/03/24 01:56:23 found no layout file for "HTML" for "home": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2020/03/24 01:56:23 found no layout file for "HTML" for "taxonomy": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2020/03/24 01:56:23 found no layout file for "HTML" for "taxonomyTerm": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2020/03/24 01:56:23 found no layout file for "HTML" for "taxonomyTerm": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2020/03/24 01:56:23 found no layout file for "HTML" for "taxonomyTerm": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2020/03/24 01:56:23 found no layout file for "HTML" for "taxonomyTerm": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.

| EN
+------------------+----+
Pages            |  6
Paginator pages  |  0
Non-page files   |  0
Static files     |  1
Processed images |  0
Aliases          |  1
Sitemaps         |  1
Cleaned          |  0
Total in 11 ms
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In other words, even with template files missing (in this case, all of them), Hugo still "successfully" builds the site. (While it wasn't the root of the problem, this is a little terrifying; I looked for an option for &lt;code&gt;hugo&lt;/code&gt; to fail on warnings, but had no such luck.)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In UNIX convention, success or failure of a command is signaled by the "exit code" (0 for success, non-zero for failure). A build will fail if any one of its commands fail. Despite that the output above looks very much like a failure to a human, the 0 exit code means "success" to the builder.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Cloning Submodules
&lt;/h2&gt;

&lt;p&gt;In any case, the reason the template files were missing is that my theme is separate repo, included as a Git submodule.  This enables me to develop both as separate public projects without one polluting the other. As I learned, though, running &lt;code&gt;git clone&lt;/code&gt; will not include a repo's submodules by default (notice the empty &lt;code&gt;rewritable.hugo&lt;/code&gt; directory below):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone git@gitlab.com:rewritable/rewritable.me.git

...

$ tree rewritable.me/themes/ -L 2
rewritable.me/themes/
└── rewritable.hugo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It's possible to clone a repo along with its submodules (and their submodules), all in one command, by passing the &lt;code&gt;--recurse-submodules&lt;/code&gt; option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone --recurse-submodules git@gitlab.com:rewritable/rewritable.me.git

...

$ tree rewritable.me/themes/ -L 2
rewritable.me/themes/
└── rewritable.hugo
    ├── archetypes
    ├── assets
    ├── layouts
    ├── UNLICENSE.md
    ├── config.toml
    └── theme.toml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In my case, I needed a command to pull them down after having cloned and changed to the directory of the main repo (the context in which the &lt;code&gt;commands&lt;/code&gt; in &lt;code&gt;amplify.yml&lt;/code&gt; are executed).&lt;/p&gt;

&lt;p&gt;That command is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git submodule update --init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;However, even my theme submodule contains a submodule (the Feather icons repo), which would not be pulled by the above command. For that, there's the &lt;code&gt;--recursive&lt;/code&gt; flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git submodule update --init --recursive
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;One last detail: pulling down my small theme repo along with its entire Git history is no big deal, but the history of popular open source projects can be expansive. When I began developing my theme, I had included the Bulma CSS framework; now there's only Feather, but I could have included both or more.&lt;/p&gt;

&lt;p&gt;Downloading the full history of even one such project can take seconds, and those add up to minutes of CPU time, which cost money (not to mention my patience).&lt;/p&gt;

&lt;p&gt;In Git parlance, cloning only the latest state of a repo, with no history, is called a "shallow clone". This is achieved by passing the &lt;code&gt;--depth&lt;/code&gt; flag, allowing to specify the desired depth of Git history in terms of commits (starting from and including the latest commit):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone --depth 1 &amp;lt;repository&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;--depth&lt;/code&gt; flag can also be passed to &lt;code&gt;git submodule update&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git submodule update --init --recursive --depth 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;git clone&lt;/code&gt; accepts a &lt;code&gt;--shallow-submodules&lt;/code&gt; flag to achieve the same:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I updated the build commands like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# amplify.yml

version: 0.1
frontend:
  phases:
    build:
      commands:
        - git submodule update --init --recursive --depth 1
        - hugo
  artifacts:
    baseDirectory: public
    files:
      - '**/*'
  cache:
    paths: []
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Building With an Arbitrary Version of Hugo
&lt;/h2&gt;

&lt;p&gt;The next build failed with a new error: "this feature is not available in your current Hugo version".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Executing command: hugo
Building sites …
ERROR 2020/03/24 08:55:10 error: failed to transform resource: TOCSS: failed to transform "css/main.scss" (text/x-scss): this feature is not available in your current Hugo version, see https://goo.gl/YMrWcn for more information
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://gohugo.io/troubleshooting/faq/#i-get-tocss--this-feature-is-not-available-in-your-current-hugo-version"&gt;linked documentation&lt;/a&gt; explains that SCSS processing is available only in the extended version, which is not installed by default on AWS.&lt;/p&gt;

&lt;p&gt;From their Dockerfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;## Install Hugo
RUN wget https://github.com/gohugoio/hugo/releases/download/v${VERSION_HUGO}/hugo_${VERSION_HUGO}_Linux-64bit.tar.gz &amp;amp;&amp;amp; \
    tar -xf hugo_${VERSION_HUGO}_Linux-64bit.tar.gz hugo -C / &amp;amp;&amp;amp; \
    mv /hugo /usr/bin/hugo &amp;amp;&amp;amp; \
    rm -rf hugo_${VERSION_HUGO}_Linux-64bit.tar.gz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Amplify does &lt;a href="https://docs.aws.amazon.com/amplify/latest/userguide/custom-build-image.html#setup-live-updates"&gt;provide an option&lt;/a&gt; to configure the value of the &lt;code&gt;VERSION_HUGO&lt;/code&gt; environment variable, but it wasn't a viable option here.&lt;/p&gt;

&lt;p&gt;The latest extended release archive looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hugo_extended_0.68.3_Linux-64bit.tar.gz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So setting &lt;code&gt;VERSION_HUGO&lt;/code&gt; to &lt;code&gt;extended_0.68.3&lt;/code&gt; would result in the correct file name. However, &lt;code&gt;VERSION_HUGO&lt;/code&gt; is interpolated in two places:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.../download/v${VERSION_HUGO}/hugo_${VERSION_HUGO}_Linux-64bit.tar.gz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Setting it to &lt;code&gt;extended_0.68.3&lt;/code&gt; would look for the archive under the nonexistent subdirectory, &lt;code&gt;vextended_0.68.3&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.../download/vextended_0.68.3/hugo_extended_0.68.3_Linux-64bit.tar.gz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The real URL resembles the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.../download/v0.68.3/hugo_extended_0.68.3_Linux-64bit.tar.gz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I opted for the solution &lt;a href="https://gohugo.io/hosting-and-deployment/hosting-on-aws-amplify/#using-a-newer-version-of-hugo"&gt;described in the Hugo docs&lt;/a&gt;, which amounts to breaking the bash one-liner from the &lt;code&gt;RUN&lt;/code&gt; step in the Dockerfile...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RUN wget https://github.com/gohugoio/hugo/releases/download/v${VERSION_HUGO}/hugo_${VERSION_HUGO}_Linux-64bit.tar.gz &amp;amp;&amp;amp; \
    tar -xf hugo_${VERSION_HUGO}_Linux-64bit.tar.gz hugo -C / &amp;amp;&amp;amp; \
    mv /hugo /usr/bin/hugo &amp;amp;&amp;amp; \
    rm -rf hugo_${VERSION_HUGO}_Linux-64bit.tar.gz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;...into a series of steps within the build configuration (build commands follow the same logic specified by &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, where the next command in sequence is only executed if the previous was successful).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# amplify.yml

version: 0.1
frontend:
  phases:
    build:
      commands:
        - git submodule update --init --recursive --depth 1
        - wget https://github.com/gohugoio/hugo/releases/download/v0.68.3/hugo_extended_0.68.3_Linux-64bit.tar.gz
        - tar -xf hugo_extended_0.68.3_Linux-64bit.tar.gz hugo
        - mv hugo /usr/bin/hugo
        - rm -rf hugo_extended_0.68.3_Linux-64bit.tar.gz
        - hugo
  artifacts:
    baseDirectory: public
    files:
      - '**/*'
  cache:
    paths: []
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The one change was to extract &lt;code&gt;hugo&lt;/code&gt; to the local directory, not the root directory (so, removing the &lt;code&gt;- C /&lt;/code&gt; option from the &lt;code&gt;tar&lt;/code&gt; command , and the leading slash in &lt;code&gt;mv /hugo&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;I'm not sure why (probably something to do with sandboxing or permissions), but extracting to the root directory did not work. The &lt;code&gt;mv&lt;/code&gt; command failed because &lt;code&gt;/hugo&lt;/code&gt; did not exist.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And that was it! The next build was a success. I'm now able to publish articles or deploy any other updates with a simple &lt;code&gt;git push&lt;/code&gt; to the master branch.&lt;/p&gt;

</description>
      <category>hugo</category>
      <category>git</category>
      <category>submodules</category>
      <category>amplify</category>
    </item>
  </channel>
</rss>
