Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Creates tokens for accessing ActiveRecord objects
Ruby
branch: master
Failed to load latest commit information.
lib update version for release
spec Update rspec syntax
.gitignore Set up gem infrastructure
.rspec COLOR RSPEC!
.travis.yml Add in most recent rubies to travis build
Gemfile Set up gem infrastructure
License.txt License
README.md
Rakefile Set up gem infrastructure
has_tokens.gemspec Update gem metadata to include license + homepage

README.md

Build Status Code Climate

Has Tokens

Creates tokens for accessing ActiveRecord objects. Allows you to declaratively specify token-based access for your ActiveRecord objects.

Under the covers, has_tokens uses SecureRandom.hex so they'll be all "c07a2". The size is configurable, so if you need a token that is trillions of characters long, you can make that happen, man.

Install

gem install has_tokens

Active Record Implementation

  1. Create a Migration to add a string "public_token" to your model
  2. Index that public_token field
class YourSuperActiveRecordClass < ActiveRecord::Base
  HasTokens.on self
  has_tokens public: 5

  before_validation :generate_tokens, on: :create
  validates_uniqueness_of :public_token

  def self.for_token(token)
    find_by_public_token!(token)
  end

  def to_param
    public_token
  end
end

Now, your urls will be tokenized "/models/5245c"

Note, if you have a bunch of models, you'll want to generate tokens for each using generate_tokens (and then save the model).

So, you first include has_tokens in your class with HasTokens.on self. Then, the has_tokens will define your public_token method.

PORO (ruby object) Implementation

class YourHipsterClass
  HasTokens.on self
  has_tokens public: 5
  def initialize
    generate_tokens
  end
end

You know, or whatever.

Authors

Corey Haines and Josh Cheek

License

Please see License.txt

Something went wrong with that request. Please try again.