mm_uses_uuid 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/mm_uses_uuid/version.rb +1 -1
- data/lib/mm_uses_uuid.rb +41 -43
- data/mm_uses_uuid.gemspec +3 -3
- metadata +6 -6
data/lib/mm_uses_uuid/version.rb
CHANGED
data/lib/mm_uses_uuid.rb
CHANGED
@@ -103,55 +103,53 @@ module MmUsesUuid
|
|
103
103
|
|
104
104
|
end
|
105
105
|
|
106
|
-
|
106
|
+
|
107
|
+
def find_new_uuid(options = {})
|
107
108
|
|
108
|
-
|
109
|
+
options = {force_safe: false}.merge(options)
|
109
110
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
else
|
117
|
-
find_new_uuid_safely(options[:ensure_unique_in])
|
118
|
-
end
|
119
|
-
|
111
|
+
if not options[:ensure_unique_in]
|
112
|
+
@_id, variant = make_uuid
|
113
|
+
#puts "assuming #{variant} UUID #{@_id} is available"
|
114
|
+
return
|
115
|
+
else
|
116
|
+
find_new_uuid_safely(options[:ensure_unique_in])
|
120
117
|
end
|
121
|
-
|
122
|
-
def find_new_uuid_safely(coll)
|
123
118
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
#puts "CHECKING #{coll} collection for availability of #{variant} UUID: #{trial_id}"
|
128
|
-
if coll.where(:_id => trial_id).fields(:_id).first.nil?
|
129
|
-
@_id = trial_id
|
130
|
-
end
|
131
|
-
end while @_id.nil?
|
119
|
+
end
|
120
|
+
|
121
|
+
def find_new_uuid_safely(coll)
|
132
122
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
uuid[-1] = replacement_lsn.to_s(16)
|
123
|
+
@_id = nil
|
124
|
+
begin
|
125
|
+
trial_id, variant = make_uuid
|
126
|
+
#puts "CHECKING #{coll} collection for availability of #{variant} UUID: #{trial_id}"
|
127
|
+
if coll.where(:_id => trial_id).fields(:_id).first.nil?
|
128
|
+
@_id = trial_id
|
140
129
|
end
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
def id_to_s
|
151
|
-
copy = self.clone
|
152
|
-
copy.instance_variable_set '@_id', @_id.to_s
|
153
|
-
copy
|
130
|
+
end while @_id.nil?
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
def make_uuid
|
135
|
+
uuid = SecureRandom.uuid.gsub!('-', '')
|
136
|
+
lsn_class = UuidModel.class_variable_get('@@lsn_class')
|
137
|
+
if replacement_lsn = lsn_class.index(self.class)
|
138
|
+
uuid[-1] = replacement_lsn.to_s(16)
|
154
139
|
end
|
155
|
-
|
140
|
+
bson_encoded_uuid = BSON::Binary.new(uuid, BSON::Binary::SUBTYPE_UUID)
|
141
|
+
return bson_encoded_uuid, 'random'
|
156
142
|
end
|
143
|
+
|
144
|
+
def id_to_s!
|
145
|
+
@_id = @_id.to_s
|
146
|
+
self
|
147
|
+
end
|
148
|
+
|
149
|
+
def id_to_s
|
150
|
+
copy = self.clone
|
151
|
+
copy.instance_variable_set '@_id', @_id.to_s
|
152
|
+
copy
|
153
|
+
end
|
154
|
+
|
157
155
|
end
|
data/mm_uses_uuid.gemspec
CHANGED
@@ -16,8 +16,8 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = MmUsesUuid::VERSION
|
17
17
|
gem.license = 'MIT'
|
18
18
|
|
19
|
-
gem.add_development_dependency "rspec", "
|
20
|
-
gem.add_development_dependency "bson_ext", "
|
21
|
-
gem.add_dependency "mongo_mapper", "
|
19
|
+
gem.add_development_dependency "rspec", ">= 2.7"
|
20
|
+
gem.add_development_dependency "bson_ext", ">= 1.5.0"
|
21
|
+
gem.add_dependency "mongo_mapper", ">= 0.10.1"
|
22
22
|
|
23
23
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 11
|
9
|
+
version: 0.0.11
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jonathan Chambers
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-
|
17
|
+
date: 2012-03-03 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -23,7 +23,7 @@ dependencies:
|
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
segments:
|
29
29
|
- 2
|
@@ -37,7 +37,7 @@ dependencies:
|
|
37
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
38
|
none: false
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
segments:
|
43
43
|
- 1
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
55
|
-
- -
|
55
|
+
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
segments:
|
58
58
|
- 0
|