Module: MmUsesUuid::ClassMethods
- Defined in:
- lib/mm_uses_uuid.rb
Instance Method Summary collapse
- #add_class_lsn(klass, lsn_integer) ⇒ Object
- #convert_ids_to_BSON(args) ⇒ Object
- #find(*args) ⇒ Object
- #find!(*args) ⇒ Object
- #new(params = {}) ⇒ Object
- #uuid_lsn(lsn_integer) ⇒ Object
Instance Method Details
#add_class_lsn(klass, lsn_integer) ⇒ Object
100 101 102 |
# File 'lib/mm_uses_uuid.rb', line 100 def add_class_lsn(klass, lsn_integer) UuidModel.class_eval "@@lsn_class[#{lsn_integer}] = #{klass}" end |
#convert_ids_to_BSON(args) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/mm_uses_uuid.rb', line 75 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
65 66 67 68 |
# File 'lib/mm_uses_uuid.rb', line 65 def find(*args) args = convert_ids_to_BSON(args) super(args) end |
#find!(*args) ⇒ Object
70 71 72 73 |
# File 'lib/mm_uses_uuid.rb', line 70 def find!(*args) args = convert_ids_to_BSON(args) super(args) end |
#new(params = {}) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/mm_uses_uuid.rb', line 85 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
96 97 98 |
# File 'lib/mm_uses_uuid.rb', line 96 def uuid_lsn(lsn_integer) add_class_lsn(self, lsn_integer) end |