Skip to content

dominicsayers/subdomain_name

Repository files navigation

SubdomainName

Gem Version Gem downloads Build Status Maintainability Test Coverage Dependency Status security Codacy Badge

SubdomainName is a Ruby gem that helps validate subdomain names that you might use in your app, for instance to allocate to users' accounts.

Usage

SubdomainName['foobar'].valid? # => true
SubdomainName['foobar'].reserved? # => false

SubdomainName['-foobar-'].valid? # => false

SubdomainName['www'].valid? # => true
SubdomainName['www'].reserved? # => true

SubdomainName['räksmörgås'].valid? # => true
SubdomainName['räksmörgås'].idn? # => true

SubdomainName['räksmörgås'].to_ascii # => xn--rksmrgs-5wao1o
SubdomainName['xn--rksmrgs-5wao1o'].to_unicode # => räksmörgås

Installation

Add this line to your application's Gemfile:

gem 'subdomain_name'

and bundle.

You may find the bundler cannot install the idn-ruby gem because it depends on the LibIDN system library which may be missing. To install this library on Ubuntu, try

sudo apt-get install libidn11-dev

On MacOS, try

brew install libidn

This library handles international subdomain names.

International domains

Domain names can include Unicode characters, e.g. räksmörgås.com. To validate these we can transform them into a format called Punycode. This is done by gem called idn.

Reserved subdomains

If you issue subdomains for an app there are some that ought to be reserved (i.e. not issued to a user), like mail and www. The reserved? method tells you whether a subdomain name should be reserved. Whether a subdomain is reserved or not is determined by the ReservedSubdomain gem.

Contributing

  1. Fork the repo into your own account.
  2. Copy the Gemfile.local.example to Gemfile.local and edit as you see fit.
  3. Organize your changes into easy-to-understand commits.
  4. Submit a pull request for me to merge.

About

A Ruby gem for managing subdomain names

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages