Class: BsonUuid

Inherits:
Object
  • Object
show all
Defined in:
lib/mm_uses_uuid.rb

Class Method Summary collapse

Class Method Details

.from_mongo(value) ⇒ Object



17
18
19
# File 'lib/mm_uses_uuid.rb', line 17

def self.from_mongo(value)
  value
end

.to_mongo(value) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/mm_uses_uuid.rb', line 6

def self.to_mongo(value)
  case value
  when String
    BSON::Binary.new(value.gsub('-', ''), BSON::Binary::SUBTYPE_UUID)
  when BSON::Binary, NilClass
    value
  else
    raise "BsonUuid cannot be of type #{value.class}. String, BSON::Binary and NilClass are the only permitted types"
  end 
end