Socket
Book a DemoInstallSign in
Socket

hash_identable

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hash_identable

1.0.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

HashIdentable

Why expose your public ID's if you don't need to? Hang hash_identable on your rails models and use the #uuid method to get a unique id of any item.

Credits

This gem wraps the hashids.org ruby gem: http://hashids.org/ruby/

Installation

Add this line to your application's Gemfile:

gem 'hash_identable', :git => 'https://github.com/octaviuslabs/hash_identable.git'

And then execute:

$ bundle

Usage

Assuming your model

  class MyModel
    attr_reader :id #HashIdentable depends on the presence of an ID
    # Other code
  end

Configure the gem

  HashIdentable.config do |c|
    c.set_salt "My Salt"  #THIS VALUE SHOULD NEVER CHANGE FOR THE APPLICATION
    c.set_length 36
    c.add_object MyModel, 3
  end

When you want the hashid:

  obj = MyModel.new(id: 12)
  obj.uuid

Or:

  obj = MyModel.new(id: 12)
  obj.identity.to_s

When you want to find an object based on the hashid:

  obj = HashIdentable::Locator.find([<find_method>], id) # Non ActiveRecord
  obj = HashIdentable::Locator::ActiveRecord.find(id) #ActiveRecord

Contributing

  • Fork it ( https://github.com/[my-github-username]/hash_identable/fork )
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create a new Pull Request

FAQs

Package last updated on 21 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.