Code Monkey home page Code Monkey logo

super_id's Introduction

SuperId

Disguise your model ID's when displayed in the UI or API

Installation

Add this line to your application's Gemfile:

gem 'super_id'

And then execute:

$ bundle

Or install it yourself as:

$ gem install super_id

Usage

In your model, you can use super id for the primary key

# app/models/flock.rb

class Flock < ActiveRecord::Base
  has_many :seagulls

  use_super_id_for :id
end

You can use super id for foreign keys too:

# app/models/seagull.rb

class Seagull < ActiveRecord::Base
  belongs_to :flock

  use_super_id_for [:id, :flock_id]
end

Options

:as

SuperId potentially supports multiple encoding algorithms, but currently is limited to short uid.

Optional Default: :short_id

# app/models/flock.rb
class Flock < ActiveRecord::Base
  has_many :seagulls

  use_super_id_for :id, as: :short_uid
end

Encoding Algorithms

Each encoding algorithm may have options of its own, which can be added to the use_super_id_for arguments.

Short UID

Options and defaults

  • salt: ''
  • min_hash_length: 0
  • alphabet: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'

For example, you can use a different salt for each model, and it will encode equal id's differently:

# app/models/flock.rb
class Flock < ActiveRecord::Base
  has_many :seagulls

  use_super_id_for :id, as: :short_uid, salt: 'foo'
end

# app/models/seagull.rb
class Seagull < ActiveRecord::Base
  belongs_to :flock

  use_super_id_for [:id, :flock_id], as: :short_uid, salt: 'bar'
end

Contributing

  1. Fork it ( https://github.com/[my-github-username]/encodable_ids/fork )
  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 a new Pull Request

super_id's People

Contributors

cuperman avatar derekcannon avatar

Watchers

Eric M. Johnston avatar Nathan Gopen avatar Mitri Abou-Rizk avatar Paulo Delgado avatar Talha Saifi avatar  avatar Jonathon Michael Golden avatar  avatar Raj Nijjar avatar Verve App Builder avatar Anthony To avatar Brian Crook avatar Kai Guo avatar Kevin English avatar Gary Damm avatar  avatar Grace Blackburn avatar mcouper avatar  avatar  avatar Amala Mani avatar Roger Perez avatar  avatar Jonathan DeLanders avatar Bryan Keelon avatar Adam Ingram-Goble avatar Brandon Dunton avatar Alan Orther avatar Taylor Bloom avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.