Sha256: 73465ccd3485db348f5b8528d4b102980d7028285879a28f05ee6257174ac837

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

= vidibus-uuid

This gem is part of the open source SOA framework Vidibus: http://www.vidibus.org

It generates compact UUIDs. Basically, this is an abstraction of http://github.com/assaf/uuid


== Installation

Add the dependency to the Gemfile of your application:

  gem "vidibus-uuid"

Then call bundle install on your console.


== Usage

  Vidibus::Uuid.generate
  # => "b063263064e0012d47b658b035f038ab"


=== Usage in Mongoid model

Include the Vidibus::Uuid::Mongoid module in your Mongoid model:

  class MyModel
    include Mongoid::Document
    include Vidibus::Uuid::Mongoid
  end

This will extend your model as follows:

  class MyModel
    include Mongoid::Document
  
    field :uuid
    index :uuid, :unique => true
  
    before_validation :generate_uuid
    validates :uuid, :uniqueness => true, :uuid => true
  
    private
  
    def generate_uuid
      return unless new_record?
      self.uuid ||= Vidibus::Uuid.generate
    end
  end


=== Validation of custom attributes

To verfify that custom attributes are formatted as UUID, add the uuid validator to your model:

  class MyModel
    include Mongoid::Document
    field :product_uuid
    validates :product_uuid, :uuid => { :allow_blank => true }
  end


== Copyright

Copyright (c) 2010 Andre Pankratz. See LICENSE for details.


== Thank you!

The development of this gem was sponsored by Käuferportal: http://www.kaeuferportal.de

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vidibus-uuid-0.3.5 README.rdoc