DEV Community

Michael Kohl
Michael Kohl

Posted on • Updated on • Originally published at

RubyRef — easy access to Ruby documentation

I don’t know about you, but I can’t really remember the last time I added a bookmark to my browser (at least not on purpose, -D is right next to -F after all). So when I saw, I knew I wanted to build something like this for the Ruby community, which is now available as


RubyRef defines a list of CNAME records of the form * which redirect to different Ruby related documentation sites. For example brings you to the core documentation, whereas redirects to the C API documentation and will take you to the awesome-ruby repository on GitHub.


Update: It's now a static site generated with Middleman and hosted on Netlify, but the CloudFlare page rules are still used, as is the Rake task.

Manually defining a bunch of CNAMEs is not what I call a fun afternoon activity, but writing code is. So RubyRef uses a Roda app in combination with Cloudflare page rules to achieve its goal. Let’s have a look at the app first (current code / roda branch):

# frozen_string_literal: true

require 'roda'
require 'json'

class RubyRef < Roda
  REDIRECTS = JSON.parse('redirects.json'))

  plugin :assets, css: 'style.css'
  plugin :render

  route do |r|

    r.root do
      render :index

    r.on 'redirect', String do |subdomain|
      r.redirect REDIRECTS.fetch(subdomain) { '/' }

    r.redirect '/'
Enter fullscreen mode Exit fullscreen mode

This reads a list of redirects from a file called redirects.json, where the various CNAMEs are mapped to their respective target URLs. The actual redirects happen through requests of the form GET<CNAME> and the code necessary to achieve this couldn’t be any simpler.

However, in the interest of less typing and faster autocompletes the redirects should be of the form https://<CNAME> and to achieve that the following Cloudflare page rule is used:

Cloudflare page rule

So far so good, there’s however one last problem: Cloudflare does not offer proxying for wildcard CNAMEs in their free tier, so I wrote a little Rake task using the Cloudflare gem to automatically add “dummy” CNAMEs pointing to “” via the Cloudflare API:

namespace :cloudflare do
  desc 'Update Cloudflare CNAMEs'
  task :update_cnames do
    redirects = JSON.parse('redirects.json'))

    email = ENV.fetch('CLOUDFLARE_EMAIL')
    key = ENV.fetch('CLOUDFLARE_KEY')
    zone_id = ENV.fetch('CLOUDFLARE_ZONE')

    connection = Cloudflare.connect(key: key, email: email)
    zone = connection.zones.find_by_id(zone_id)
    cnames = { |dns| dns.record[:type] == 'CNAME' }! { |cname| cname.record[:name] }

    redirects.each_key do |cname|
      name = "#{cname}"
      next if cnames.include?(name)

      puts "Setting CNAME: #{name}"
          type: 'CNAME',
          name: name,
          content: '',
          proxied: true
        content_type: 'application/json'
Enter fullscreen mode Exit fullscreen mode

With all the CNAMEs defined the page rule now works and the Roda app takes care of the rest 🎉


If you want to see new sites added to RubyRef, just open a PR with the extra lines added to redirects.json and I will take care of the rest.

Discussion (3)

ghost profile image

Hi Michael, what a great addition to the Ruby community. PLEASE be sure and make sure RUby Weekly and some of the other Ruby news outlets know about it.


citizen428 profile image
Michael Kohl Author

I'll do that. You can always help spread the word, I don't like going out and tooting my own horn too much. In the past Ruby Weekly has picked up my stuff organically, but this seems to not have made it on their radar.

ghost profile image

Done.. Submitted to Hasnode and Rubyflow (which is the same publisher that publish Ruby Weekly)