primary_key-uuid-rails 0.0.5 → 0.0.6
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ff7972cb1d8155cfdf0f80af1de8abaec05b11b
|
4
|
+
data.tar.gz: 45af93254cfcc33b02aabee44d3b861ef15b977e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca0a2d53d7d1fefe8223edb0e0db1c9bc46f2533388f894123bd7325239cc5f59d3ea40b8eac8620434e04eda714b9016708fba47574cab8c175e011df0ff8fd
|
7
|
+
data.tar.gz: cc32ce24285fedcfc3182655c0e31d926ebdf4804841e06c36553805ab3883d8f37282e2bb6063c492fb7a0e4f64aff2bd526fcff58c10cd776398c46852ad47
|
@@ -6,6 +6,14 @@ module PrimaryKey
|
|
6
6
|
require "primary_key/uuid/rails/patch"
|
7
7
|
end
|
8
8
|
end
|
9
|
+
def self.generate
|
10
|
+
namespace (DateTime.now.to_i*1000000 + DateTime.now.usec)
|
11
|
+
end
|
12
|
+
def self.namespace identifier
|
13
|
+
@uuid_namespace ||= UUIDTools::UUID.parse "f90fe61d-1778-08a4-308a-3beaa8d3c44c"
|
14
|
+
@application_namespace ||= UUIDTools::UUID.sha1_create(@uuid_namespace,::Rails.application.class.parent_name)
|
15
|
+
UUIDTools::UUID.sha1_create(@application_namespace,identifier.to_s)
|
16
|
+
end
|
9
17
|
end
|
10
18
|
end
|
11
19
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require "uuidtools"
|
2
2
|
|
3
3
|
class ActiveRecord::Base
|
4
|
-
|
4
|
+
after_initialize :set_primary_key_uuid
|
5
5
|
private
|
6
6
|
def set_primary_key_uuid
|
7
7
|
return unless self.class.primary_key
|
8
8
|
pk = self.class.primary_key
|
9
9
|
return unless self.class.columns_hash[pk].sql_type == "uuid"
|
10
|
-
id = ::
|
10
|
+
id = ::PrimaryKey::Uuid::Rails.generate
|
11
11
|
puts self.send(pk)
|
12
12
|
return unless self.send(pk).nil?
|
13
13
|
puts "Set id to #{id}"
|