SubdomainName
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
- Fork the repo into your own account.
- Copy the
Gemfile.local.example
toGemfile.local
and edit as you see fit. - Organize your changes into easy-to-understand commits.
- Submit a pull request for me to merge.