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: 964aa9bb9b781c8ca90803f8117130daf1aac1ea88324ab64237b0e2a6a6c328
4
- data.tar.gz: 834dd56d5e39fdad058efa794f1e5022b92d9122463c827d91d85ffcd9dbe291
3
+ metadata.gz: 3facd27f1d4401d01c3e42dc9ab11d75652cc6859a74c5c74ffb58647b13c28d
4
+ data.tar.gz: 48072021ae935b5c7d9a684f488dafb3ffa53b94ea153bfeeba7f1b5f5a46806
5
5
  SHA512:
6
- metadata.gz: ff532ebd5b3750554a63786877d846c724e5edb28796f964977b7bc03064eada4ea3c608d0b0809a4306306c5bb75dfedc0ed5fa670ef7fb2b224b39ebcaafcc
7
- data.tar.gz: '0886f5a8caad820a963af4d37a07fb319ae5cfc8735f400f41eb22131df9f90477b966d91f3e2f26e40bffc1579bcbc9bba2dd351cb677a28df90dea87368eef'
6
+ metadata.gz: b884394e95a3c722c8a3a1327780700f153f9e724c920d9d57e81409d836e5111777f3493b504bfe7b6321a1d83ed95f6fe2613b9f77677393d2caab631caa4e
7
+ data.tar.gz: 6891f2e8a291d4a72c725ce09a7270681ed8e2f7485d2f68d195f6fc0f55005e07408855f194d1ac130fe3c874c59c3bdc4e5aa87b512b776c37be792dd5e605
@@ -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
- # We use a class var here because this is a global registry for all subclasses
17
- # of this namespace
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 = @@registry[content_type]
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
- @@registry[content_type] = klass
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 @@registry
150
+ return {} unless _registry
152
151
 
153
- @@registry.dup.freeze
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
- @@registry[content_type]
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 WCC::Contentful::Model.registered?(content_type)
72
+ return if model_namespace.registered?(content_type)
73
73
 
74
- WCC::Contentful::Model.register_for_content_type(content_type, klass: subclass)
74
+ model_namespace.register_for_content_type(content_type, klass: subclass)
75
75
  end
76
76
 
77
77
  class ModelQuery
@@ -2,6 +2,6 @@
2
2
 
3
3
  module WCC
4
4
  module Contentful
5
- VERSION = '1.1.1'
5
+ VERSION = '1.1.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wcc-contentful
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Watermark Dev