rdelandesen / hashable

Hashable allows you to generate and save hash id for ActiveRecord models.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hashable

Hashable allows you to generate and save hash id for ActiveRecord models.

Build Status

For example :

ID Hash ID
1 ejRe
2 bk5e
3 el5a

Hashable uses HashIds.rb encoding.

N.B. If you don't need to save hash id in database, you can use HashId Rails.

Installation

Add this line to your application's Gemfile:

gem 'hashable', github: 'rdelandesen/hashable'

And then execute:

$ bundle

Usage

Model setup

class User < ActiveRecord::Base
  hashable.config do |c|
    c.attr = :hash_id
    
    # Optional
    c.source     = :id
    c.salt       = 'replaceit' # by default => ''
    c.alphabet   = 'abcdefxyz' # by default => all letters + 0..9
    c.min_length = 4 # by default
  end
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/rdelandesen/hashable.

License

The gem is available as open source under the terms of the MIT License.

About

Hashable allows you to generate and save hash id for ActiveRecord models.

License:MIT License


Languages

Language:Ruby 80.6%Language:HTML 14.5%Language:JavaScript 3.0%Language:CSS 1.9%