activeuuid 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/activeuuid/uuid.rb +15 -2
- data/lib/activeuuid/version.rb +1 -1
- metadata +4 -4
data/lib/activeuuid/uuid.rb
CHANGED
@@ -40,18 +40,31 @@ module ActiveUUID
|
|
40
40
|
|
41
41
|
set_primary_key "id"
|
42
42
|
serialize :id, ActiveUUID::UUIDSerializer.new
|
43
|
-
|
44
43
|
|
45
44
|
def generate_uuid_if_needed
|
46
45
|
generate_uuid unless self.id
|
47
46
|
end
|
48
47
|
|
49
48
|
def generate_uuid
|
50
|
-
|
49
|
+
if nka = self.class.natural_key_attributes
|
50
|
+
# TODO if all the attributes return nil you might want to warn about this
|
51
|
+
chained = nka.collect{|a| self.send(a).to_s}.join("-")
|
52
|
+
self.id = UUIDTools::UUID.sha1_create(UUIDTools::UUID_OID_NAMESPACE, chained)
|
53
|
+
else
|
54
|
+
self.id = UUIDTools::UUID.timestamp_create
|
55
|
+
end
|
51
56
|
end
|
52
57
|
end
|
53
58
|
|
54
59
|
module ClassMethods
|
60
|
+
def natural_key_attributes
|
61
|
+
@_activeuuid_natural_key_attributes
|
62
|
+
end
|
63
|
+
|
64
|
+
def natural_key(*attributes)
|
65
|
+
@_activeuuid_natural_key_attributes = attributes
|
66
|
+
end
|
67
|
+
|
55
68
|
#def uuids(*attributes)
|
56
69
|
# attributes.each do |attribute|
|
57
70
|
# class_eval <<-eos
|
data/lib/activeuuid/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeuuid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-30 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: uuidtools
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156315740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156315740
|
25
25
|
description: Add's binary (not string) UUIDs to ActiveRecord in MySQL
|
26
26
|
email:
|
27
27
|
- nate@natemurray.com
|