Module: Uuidify::UuidifyConcern::ClassMethods

Defined in:
lib/uuidify/uuidify_concern.rb

Instance Method Summary collapse

Instance Method Details

#garbage_collect_uuidsObject

Delete entries where we don’t have a model that can be instantiated anymore.



29
30
31
32
33
34
35
# File 'lib/uuidify/uuidify_concern.rb', line 29

def garbage_collect_uuids
  Uuidify::Uuid.where(:model_name => self.to_s).find_each do |uuid|
    if !where(:id => uuid.model_id).first
      uuid.destroy
    end
  end
end

#lookup_uuid(uuid) ⇒ Object

.find_by_uuid. Used lookup so we know it’s not rails magic.



21
22
23
24
25
26
# File 'lib/uuidify/uuidify_concern.rb', line 21

def lookup_uuid(uuid)
  uuid = Uuidify::Uuid.uuid_to_sql_string(uuid)
  
  uuid = Uuidify::Uuid.where(:model_uuid => uuid, :model_name => self.to_s).first
  uuid ? find(uuid.model_id) : nil
end