Sha256: 267d32c0ddfaf1e3c27e38a29d87b4d2ec0e8ccfdb9e48330c3960acdcda57cc
Contents?: true
Size: 1.15 KB
Versions: 4
Compression:
Stored size: 1.15 KB
Contents
# = Uuidify # # Add UUIDs to existing ActiveRecord models. # # To install: # # rake uuidify:install:migrations # rake db:migrate # # To enable on a specific model: # # class Foo < ActiveRecord::Base # uuidify # end # # To get/set uuids: # # Foo.new.uuid # Foo.new.uuid = UUIDTools::UUID.timestamp_create # # To gc orphan records: # # Foo.garbage_collect_uuids # single model # Uuidify.garbage_collect_uuids # everything, even if the model doesn't exist in the source require 'uuidify/engine' require 'uuidify/uuidify_concern' # Helper like acts_as_X so we don't deal with the concern mixin directly. def uuidify include Uuidify::UuidifyConcern end module Uuidify # Clean up all orphaned and useless UUIDs in the database, whether or not we can # resolve them to a class. def self.garbage_collect_uuids Uuidify::Uuid.select("model_name").group("model_name").each do |m| begin klass = m.model_name.constantize klass.garbage_collect_uuids rescue NameError => ex # Class that doesn't exist in current project Uuidify::Uuid.where(:model_name => m.model_name).delete_all end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
uuidify-0.5.0 | lib/uuidify.rb~ |
uuidify-0.4.0 | lib/uuidify.rb~ |
uuidify-0.3.1 | lib/uuidify.rb~ |
uuidify-0.3.0 | lib/uuidify.rb~ |