module MmUsesUuid

Constants

VERSION

Public Instance Methods

find_new_uuid(options = {}) click to toggle source
# File lib/mm_uses_uuid.rb, line 116
def find_new_uuid(options = {})
  
  options = {force_safe: false}.merge(options)
    
  if not options[:ensure_unique_in]
    @_id = make_uuid
    #puts "assuming UUID #{@_id} is available"
    return
  else
    find_new_uuid_safely(options[:ensure_unique_in])
  end

end
find_new_uuid_safely(coll) click to toggle source
# File lib/mm_uses_uuid.rb, line 130
def find_new_uuid_safely(coll)

  @_id = nil
  begin
    trial_id = make_uuid
    #puts "CHECKING #{coll} collection for availability of UUID: #{trial_id}"
    if coll.where(:_id => trial_id).fields(:_id).first.nil?
      @_id = trial_id
    end
  end while @_id.nil?

end
id_to_s() click to toggle source
# File lib/mm_uses_uuid.rb, line 152
def id_to_s
  copy = self.clone
  copy.instance_variable_set '@_id',  @_id.to_s
  copy
end
id_to_s!() click to toggle source
# File lib/mm_uses_uuid.rb, line 147
def id_to_s!
  @_id = @_id.to_s
  self
end
make_uuid() click to toggle source
# File lib/mm_uses_uuid.rb, line 143
def make_uuid
  self.class.make_uuid
end