Sha256: 22844c95a9f5428ca6c6f69981fc14bad748238bb5f9085312aae5750a5923f6

Contents?: true

Size: 426 Bytes

Versions: 7

Compression:

Stored size: 426 Bytes

Contents

# Patches ActiveRecord models to use UUID based IDs instead of the default numeric ones
require 'uuidtools'

# Extends ActiveRecord models with UUID based IDs
module RestfulX
  module UUIDHelper
    def self.included(base)
      base.class_eval do 
        before_create :generate_uuid
      end
    end
  
    def generate_uuid
      self.id = UUIDTools::UUID.random_create.to_s.gsub("-", "") unless self.id
    end
  end
end

Version data entries

7 entries across 7 versions & 4 rubygems

Version Path
captproton-restfulx-1.2.3 lib/restfulx/active_record_uuid_helper.rb
dima-restfulx-1.2.3 lib/restfulx/active_record_uuid_helper.rb
dima-restfulx-1.2.4 lib/restfulx/active_record_uuid_helper.rb
rlmattax-restfulx-1.2.4.1 lib/restfulx/active_record_uuid_helper.rb
restfulx-1.2.5 lib/restfulx/active_record_uuid_helper.rb
restfulx-1.2.3 lib/restfulx/active_record_uuid_helper.rb
restfulx-1.2.4 lib/restfulx/active_record_uuid_helper.rb