SubdomainName is a Ruby gem that helps validate subdomain names that you might use in your app, for instance to allocate to users' accounts.
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åsAdd 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.
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.
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.
- Fork the repo into your own account.
- Copy the
Gemfile.local.exampletoGemfile.localand edit as you see fit. - Organize your changes into easy-to-understand commits.
- Submit a pull request for me to merge.