wcc-contentful 1.1.1 → 1.1.2
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3facd27f1d4401d01c3e42dc9ab11d75652cc6859a74c5c74ffb58647b13c28d
|
4
|
+
data.tar.gz: 48072021ae935b5c7d9a684f488dafb3ffa53b94ea153bfeeba7f1b5f5a46806
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b884394e95a3c722c8a3a1327780700f153f9e724c920d9d57e81409d836e5111777f3493b504bfe7b6321a1d83ed95f6fe2613b9f77677393d2caab631caa4e
|
7
|
+
data.tar.gz: 6891f2e8a291d4a72c725ce09a7270681ed8e2f7485d2f68d195f6fc0f55005e07408855f194d1ac130fe3c874c59c3bdc4e5aa87b512b776c37be792dd5e605
|
data/lib/wcc/contentful/model.rb
CHANGED
@@ -41,10 +41,6 @@ require_relative './model_api'
|
|
41
41
|
class WCC::Contentful::Model
|
42
42
|
include WCC::Contentful::ModelAPI
|
43
43
|
|
44
|
-
# The Model base class maintains a registry which is best expressed as a
|
45
|
-
# class var.
|
46
|
-
# rubocop:disable Style/ClassVars
|
47
|
-
|
48
44
|
class << self
|
49
45
|
def const_missing(name)
|
50
46
|
type = WCC::Contentful::Helpers.content_type_from_constant(name)
|
@@ -53,5 +49,3 @@ class WCC::Contentful::Model
|
|
53
49
|
end
|
54
50
|
end
|
55
51
|
end
|
56
|
-
|
57
|
-
# rubocop:enable Style/ClassVars
|
@@ -13,9 +13,8 @@ module WCC::Contentful::ModelAPI
|
|
13
13
|
services.instrumentation
|
14
14
|
end
|
15
15
|
|
16
|
-
#
|
17
|
-
|
18
|
-
@@registry = {} # rubocop:disable Style/ClassVars
|
16
|
+
# Set the registry at the top of the namespace
|
17
|
+
@registry = {}
|
19
18
|
end
|
20
19
|
|
21
20
|
class_methods do
|
@@ -89,7 +88,7 @@ module WCC::Contentful::ModelAPI
|
|
89
88
|
def resolve_constant(content_type)
|
90
89
|
raise ArgumentError, 'content_type cannot be nil' unless content_type
|
91
90
|
|
92
|
-
const =
|
91
|
+
const = _registry[content_type]
|
93
92
|
return const if const
|
94
93
|
|
95
94
|
const_name = WCC::Contentful::Helpers.constant_from_content_type(content_type).to_s
|
@@ -143,14 +142,14 @@ module WCC::Contentful::ModelAPI
|
|
143
142
|
|
144
143
|
content_type ||= WCC::Contentful::Helpers.content_type_from_constant(klass)
|
145
144
|
|
146
|
-
|
145
|
+
_registry[content_type] = klass
|
147
146
|
end
|
148
147
|
|
149
148
|
# Returns the current registry of content type names to constants.
|
150
149
|
def registry
|
151
|
-
return {} unless
|
150
|
+
return {} unless _registry
|
152
151
|
|
153
|
-
|
152
|
+
_registry.dup.freeze
|
154
153
|
end
|
155
154
|
|
156
155
|
def reload!
|
@@ -176,7 +175,15 @@ module WCC::Contentful::ModelAPI
|
|
176
175
|
# that class. If nil, the generated WCC::Contentful::Model::{content_type} class
|
177
176
|
# will be resolved for this content type.
|
178
177
|
def registered?(content_type)
|
179
|
-
|
178
|
+
_registry[content_type]
|
179
|
+
end
|
180
|
+
|
181
|
+
protected
|
182
|
+
|
183
|
+
def _registry
|
184
|
+
# If calling register_for_content_type in a subclass, look up the superclass
|
185
|
+
# chain until we get to the model namespace which defines the registry
|
186
|
+
@registry || superclass._registry
|
180
187
|
end
|
181
188
|
end
|
182
189
|
end
|
@@ -69,9 +69,9 @@ module WCC::Contentful::ModelSingletonMethods
|
|
69
69
|
def inherited(subclass)
|
70
70
|
# If another different class is already registered for this content type,
|
71
71
|
# don't auto-register this one.
|
72
|
-
return if
|
72
|
+
return if model_namespace.registered?(content_type)
|
73
73
|
|
74
|
-
|
74
|
+
model_namespace.register_for_content_type(content_type, klass: subclass)
|
75
75
|
end
|
76
76
|
|
77
77
|
class ModelQuery
|