UniversalIdentifiable

Make your model uniq and identifiable through a readable name. Adds uuids to ActiveRecord models along with validators.

Build Status Gem Version Code Climate

Installation

Add this line to your application's Gemfile:

gem 'universal_identifiable'

And then execute:

$ bundle

Or install it yourself as:

$ gem install universal_identifiable

Usage

Create a migration for your existing model with the built in generator.

Example:


rails g uuid Airport

In your model:

class Airport < ActiveRecord::Base
  include UniversalIdentifiable
end

Uuids must be prefixed with the modelname and namespaced with a dot. E.G: "airport.dortmund"

Set a uuid like you would with any other attribute:

airport = Airport.new(uuid: "airport.dortmund")

You have access to an unnamespaced uuid by passing the appropriate option:

airport.uuid(namespaced: false)
=> "dortmund"
airport.uuid
=> "airport.dortmund"

Validators:

Two validators are automatically added to your model:

validates :uuid, :presence => true, :uniqueness => true

TODO:

  • Automatically save uuid with corresponding modelname, seperated with namespacer.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request