typed_uuid 3.0 → 3.1
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 +4 -4
- data/lib/typed_uuid/active_record.rb +12 -9
- data/lib/typed_uuid/version.rb +1 -1
- data/test/test_helper.rb +3 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '095cb1b693a3a64314143fc603c593a940fc9e62f6c52541d351896322a8b62a'
|
4
|
+
data.tar.gz: 5e9e510f3a93f8eac7f7ae6cc1b06b6665cc9176335f5f08678367c8c0348ad5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c0d7fbf4d5f52d337328fad41631c7999cd6c9e2fd7726c2552ade74cc5e52bb98f48f446a4063e711efa3a546e70d9f86bf9a0290d7ccb5ada6d57df5e554f
|
7
|
+
data.tar.gz: 22cd61995e15a923b614eb9c66181a9bb6f60607bd0bd33f60e1f5831aaf13219a6da1f3dfbd1bf0e63480e4fd2c7f490552b2625e38eb4944692128e7851c02
|
@@ -9,7 +9,10 @@ module TypedUUID::ActiveRecord
|
|
9
9
|
|
10
10
|
included do
|
11
11
|
class_attribute(:defined_uuid_types, instance_writer: false, default: {})
|
12
|
-
class_attribute(:
|
12
|
+
class_attribute(:class_to_uuid_type_cache, instance_writer: false, default: Hash.new { |hash, klass|
|
13
|
+
hash[klass] = defined_uuid_types.key(klass.name)
|
14
|
+
})
|
15
|
+
class_attribute(:uuid_type_to_class_cache, instance_writer: false, default: {})
|
13
16
|
end
|
14
17
|
|
15
18
|
def _create_record
|
@@ -48,7 +51,7 @@ module TypedUUID::ActiveRecord
|
|
48
51
|
end
|
49
52
|
|
50
53
|
def typed?
|
51
|
-
!!
|
54
|
+
!!class_to_uuid_type_cache[self.base_class]
|
52
55
|
end
|
53
56
|
|
54
57
|
def typed_uuid
|
@@ -60,28 +63,28 @@ module TypedUUID::ActiveRecord
|
|
60
63
|
end
|
61
64
|
|
62
65
|
def uuid_type_from_class(klass)
|
63
|
-
type =
|
64
|
-
|
66
|
+
type = class_to_uuid_type_cache[klass]
|
67
|
+
|
65
68
|
if type.nil?
|
66
69
|
raise ArgumentError, "UUID Type for \"#{klass.name}\" not defined"
|
67
70
|
end
|
68
|
-
|
71
|
+
|
69
72
|
type
|
70
73
|
end
|
71
74
|
|
72
75
|
def class_from_uuid_type(type)
|
73
|
-
|
74
|
-
|
76
|
+
klass = if uuid_type_to_class_cache.has_key?(type)
|
77
|
+
uuid_type_to_class_cache[type]
|
75
78
|
else
|
76
79
|
Rails.application.eager_load! if !Rails.application.config.eager_load
|
77
80
|
|
78
81
|
::ActiveRecord::Base.descendants.each do |klass|
|
79
82
|
next if klass.table_name.nil?
|
80
83
|
|
81
|
-
|
84
|
+
uuid_type_to_class_cache[defined_uuid_types.key(klass.name)] = klass
|
82
85
|
end
|
83
86
|
|
84
|
-
|
87
|
+
uuid_type_to_class_cache[type]
|
85
88
|
end
|
86
89
|
end
|
87
90
|
|
data/lib/typed_uuid/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -54,8 +54,9 @@ class ActiveSupport::TestCase
|
|
54
54
|
set_callback(:setup, :before) do
|
55
55
|
Rails.stubs(:application).returns(stub(config: stub(eager_load: true)))
|
56
56
|
if !self.class.class_variable_defined?(:@@suite_setup_run)
|
57
|
-
ActiveRecord::Base.defined_uuid_types
|
58
|
-
ActiveRecord::Base.
|
57
|
+
ActiveRecord::Base.defined_uuid_types.clear
|
58
|
+
ActiveRecord::Base.uuid_type_to_class_cache.clear
|
59
|
+
ActiveRecord::Base.class_to_uuid_type_cache.clear
|
59
60
|
|
60
61
|
configuration = {
|
61
62
|
adapter: "postgresql",
|