Module: MmUsesUuid::ClassMethods

Defined in:
lib/mm_uses_uuid.rb

Instance Method Summary collapse

Instance Method Details

#convert_ids_to_BSON(args) ⇒ Object



99
100
101
102
103
104
105
106
107
# File 'lib/mm_uses_uuid.rb', line 99

def convert_ids_to_BSON(args)
  args.flatten!
  if args.size > 1
    args.map! {|id| BsonUuid.to_mongo(id)}
  else
    args = BsonUuid.to_mongo(args.first)
  end
  args
end

#find(*args) ⇒ Object



89
90
91
92
# File 'lib/mm_uses_uuid.rb', line 89

def find(*args)
  args = convert_ids_to_BSON(args)
  super(args)
end

#find!(*args) ⇒ Object



94
95
96
97
# File 'lib/mm_uses_uuid.rb', line 94

def find!(*args)
  args = convert_ids_to_BSON(args)
  super(args)
end

#new(params = {}) ⇒ Object



109
110
111
112
113
114
115
116
117
118
# File 'lib/mm_uses_uuid.rb', line 109

def new(params = {})
  passed_id = params.delete(:id) || params.delete(:_id) || params.delete('id') || params.delete('_id')
  new_object = super(params)
  if passed_id.is_a?(BSON::Binary) and passed_id.subtype == BSON::Binary::SUBTYPE_UUID
    new_object.id = passed_id
  else
    new_object.find_new_uuid
  end
  new_object
end

#uuid_lsn(lsn_integer) ⇒ Object



120
121
122
# File 'lib/mm_uses_uuid.rb', line 120

def uuid_lsn(lsn_integer)
  UuidModel.add_lsn_mapping(lsn_integer, self)
end