Giter VIP home page Giter VIP logo

usesguid's Introduction

Changes in this Fork

  • Converted to Gem ported by C. Jason Harrelson (midas)

DETAILS

This plugin for ActiveRecord makes the “ID” field into a URL-safe GUID It is a mashup by Andy Singleton <[email protected]> that includes

  • the UUID class from Bob Aman.

  • the plugin skeleton from Demetrius Nunes

  • the 22 character URL-safe format from Andy Singleton

You can get standard 36 char UUID formats instead TODO: Auto-detect a character ID field and use a GUID in this case (DRY principle)

It has been extended by Brian Morearty with:

  • the addition of a mysql_create function (configurable with a guid_generator accessor) for much better performance

  • id assignment is now done before_create instead of after_initialize, to more closely mimic the default Rails behavior of assigning an id upon save.

This library is free software; you can redistribute it and/or modify it under the terms of the MIT license.

USAGE

define ID as char(22) call “usesguid” in ActiveRecord class declaration, like:

class Mymodel < ActiveRecord::Base
  usesguid			
end

If your ID field is not called “ID”, call “usesguid :column =>‘IdColumnName’”

In order to use a GUID in another field that is not your primary key, id call usesguid like:

class Mymodel < ActiveRecord::Base
  usesguid, :as => :field
end

If you would like to validate your GUID a validation macro is provided:

class Mymodel < ActiveRecord::Base
  usesguid, :as => :field

  validate_guid
end

validate_guid is the same as:

validates_presence_of( ActiveRecord::Base.guid_column )
validates_uniqueness_of( ActiveRecord::Base.guid_column )
validates_length_of( ActiveRecord::Base.guid_column, :maximum => (ActiveRecord::Base.guid_compression == 's22' ? 22 : 36), :allow_blank => true )

If you use MySQL or SQL Server as your database, you can make guid generation much faster by using the database to generate GUIDs.

You can accomplish this by specifying the GUID generator in an initializer file. There are also options for guid_compression and guid_column.

ActiveRecord::Base.guid_generator   = :mysql # mysql or sqlserver
ActiveRecord::Base.guid_compression = :s     # :s for string or :s22 for compressed string
ActiveRecord::Base.guid_column      = 'guid' # the name of your GUID column

usesguid's People

Stargazers

Jason Harrelson avatar

Watchers

Jason Harrelson avatar James Cloos avatar  avatar  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.