typed_uuid 3.0 → 3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43aee2470b269097c2a79848c41aaa7e2dc490b097ed0ec38e5c5dba2cc46fb1
4
- data.tar.gz: de4d70c9c051f43d14acf0f1c32b4f5e9428038e68c28e63cf41593a38294f7f
3
+ metadata.gz: '095cb1b693a3a64314143fc603c593a940fc9e62f6c52541d351896322a8b62a'
4
+ data.tar.gz: 5e9e510f3a93f8eac7f7ae6cc1b06b6665cc9176335f5f08678367c8c0348ad5
5
5
  SHA512:
6
- metadata.gz: df59f77e9cad353ade579c091532197fcc4363dba10ab2c4914c3379d839648a0c1d56bea3f42925189e6bbc9996bb98894dbe625749950a817e099c2503db37
7
- data.tar.gz: 0a047a6fed326adb9880d92138cc390faf7670fa60319b219725998fec3a15b42be239f05934e2d4a4bfd3ad0dfea43aa33c24a01030df79a62130c9ac04d81c
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(:uuid_type_cache, instance_writer: false, default: {})
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
- !!defined_uuid_types.key(self.base_class.name)
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 = defined_uuid_types.key(klass.name)
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
- if klass = uuid_type_cache[type]
74
- return klass
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
- uuid_type_cache[defined_uuid_types.key(klass.name)] = klass
84
+ uuid_type_to_class_cache[defined_uuid_types.key(klass.name)] = klass
82
85
  end
83
86
 
84
- uuid_type_cache[type]
87
+ uuid_type_to_class_cache[type]
85
88
  end
86
89
  end
87
90
 
@@ -1,3 +1,3 @@
1
1
  module TypedUUID
2
- VERSION = '3.0'
2
+ VERSION = '3.1'
3
3
  end
@@ -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.uuid_type_cache = {}
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",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typed_uuid
3
3
  version: !ruby/object:Gem::Version
4
- version: '3.0'
4
+ version: '3.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy