wcc-contentful 1.4.0.rc1 → 1.4.0.rc3

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: 40c4c53ea7b5054745f8cd28841d59934a2e83ea65e4658e64124533412500bb
4
- data.tar.gz: 53150802f51676dafc356812578159c23670335b8066c0536ad0d0b89fb094fd
3
+ metadata.gz: f1c1fa12c92cfa84f2308474f177f56f015dc6c8116245b13074a64fe29eeaa5
4
+ data.tar.gz: 6ee074042103a824705738f6aeab222c302918ebf1f4fc53f37e63e0857328ba
5
5
  SHA512:
6
- metadata.gz: cd9ad6f0e34c388c12bc55fb7a62e5a55463f83fa0b09c0964e9f990d373ef142c890d54b8d77d6cd5e4e8e53a3c199919163268b2fddba7ec79e6f39e040a18
7
- data.tar.gz: 1102e99319ded82fdef9293b06f68dae7d06b978696f6c12afe094f467d8f8cfff7242ada67e2adebed4b2903e279bd637ac468569dbf79a786e3ed07244337d
6
+ metadata.gz: 4a63d99f50a9c89d5f708f8da774a178959ba3336ddb1e40503b05c32a071f00e1cb72667083caaa51b59f29f582cfa78233960d95cfe170b362d0a24160bbe4
7
+ data.tar.gz: 6e190a63485e5b22e7e772d6fee2fc545dba96daf8bdaa57ea819ae9f760cc010170ac354818f85b620167362dbfb3729d0749634e3c2217cc7f28d6160a96e1
data/README.md CHANGED
@@ -374,7 +374,6 @@ WCC::Contentful::SimpleClient::Cdn.new(
374
374
  space: '1234',
375
375
  # optional
376
376
  environment: 'staging', # omit to use master
377
- default_locale: '*',
378
377
  rate_limit_wait_timeout: 10,
379
378
  instrumentation: ActiveSupport::Notifications,
380
379
  connection: Faraday.new { |builder| ... },
@@ -51,7 +51,6 @@ module WCC::Contentful
51
51
  management_token: config.management_token,
52
52
  space: config.space,
53
53
  environment: config.environment,
54
- default_locale: config.default_locale,
55
54
  connection: config.connection,
56
55
  webhook_username: config.webhook_username,
57
56
  webhook_password: config.webhook_password,
@@ -33,7 +33,7 @@ module WCC::Contentful::ActiveRecordShim
33
33
 
34
34
  class_methods do
35
35
  def model_name
36
- WCC::Contentful::Helpers.constant_from_content_type(content_type)
36
+ ActiveModel::Name.new(self, nil, WCC::Contentful::Helpers.constant_from_content_type(content_type))
37
37
  end
38
38
 
39
39
  def const_get(name)
@@ -46,7 +46,7 @@ module WCC::Contentful::ActiveRecordShim
46
46
  end
47
47
 
48
48
  def table_name
49
- model_name.tableize
49
+ model_name.plural.tableize
50
50
  end
51
51
 
52
52
  def unscoped
@@ -26,7 +26,7 @@ module WCC::Contentful::EntryLocaleTransformer
26
26
  'WCC::Contentful::EntryLocaleTransformer:locales_included' => [entry_locale]
27
27
  })
28
28
  fields =
29
- entry['fields'].transform_values do |value|
29
+ entry['fields']&.transform_values do |value|
30
30
  h = {}
31
31
  h[entry_locale] = value
32
32
  h
@@ -50,7 +50,6 @@ module WCC::Contentful::EntryLocaleTransformer
50
50
 
51
51
  return entry
52
52
  end
53
- return entry unless entry['fields']
54
53
 
55
54
  # Transform the store's "locale=*" entry into a localized one
56
55
  locale ||= default_locale
@@ -58,7 +57,7 @@ module WCC::Contentful::EntryLocaleTransformer
58
57
  sys = entry['sys'].deep_dup
59
58
  sys['locale'] = locale
60
59
  fields =
61
- entry['fields'].transform_values do |value|
60
+ entry['fields']&.transform_values do |value|
62
61
  next if value.nil?
63
62
 
64
63
  # replace the all-locales value with the localized value
@@ -34,7 +34,8 @@ module WCC::Contentful::Middleware::Store
34
34
  # Now that the one locale is in the cache, when we index next time we'll index the
35
35
  # all-locales version and we'll be fine.
36
36
  locale = options[:locale]&.to_s || default_locale
37
- if found.dig('sys', 'locale') != locale
37
+ found_locale = found.dig('sys', 'locale')&.to_s
38
+ if found_locale && (found_locale != locale)
38
39
  event = 'miss'
39
40
  return store.find(key, **options)
40
41
  end
@@ -90,15 +91,21 @@ module WCC::Contentful::Middleware::Store
90
91
  id = json.dig('sys', 'id')
91
92
  type = json.dig('sys', 'type')
92
93
  prev = @cache.read(id)
93
- return if prev.nil? && LAZILY_CACHEABLE_TYPES.include?(type)
94
+ if prev.nil? && LAZILY_CACHEABLE_TYPES.include?(type)
95
+ _instrument('miss.index', key: id, type: type, prev: nil, next: nil)
96
+ return
97
+ end
94
98
 
95
99
  if (prev_rev = prev&.dig('sys', 'revision')) && (next_rev = json.dig('sys', 'revision')) && (next_rev < prev_rev)
100
+ _instrument('miss.index', key: id, type: type, prev: prev_rev, next: next_rev)
96
101
  return prev
97
102
  end
98
103
 
99
104
  # we also set DeletedEntry objects in the cache - no need to go hit the API when we know
100
105
  # this is a nil object
101
- @cache.write(id, json, expires_in: expires_in)
106
+ _instrument('write.index', key: id, type: type, prev: prev_rev, next: next_rev) do
107
+ @cache.write(id, json, expires_in: expires_in)
108
+ end
102
109
 
103
110
  case type
104
111
  when 'DeletedEntry', 'DeletedAsset'
@@ -59,11 +59,11 @@ module WCC::Contentful
59
59
 
60
60
  define_method(:initialize) do |raw, context = nil|
61
61
  ct = content_type_from_raw(raw)
62
- if ct != typedef.content_type
62
+ if ct.present? && ct != typedef.content_type
63
63
  raise ArgumentError, 'Wrong Content Type - ' \
64
64
  "'#{raw.dig('sys', 'id')}' is a #{ct}, expected #{typedef.content_type}"
65
65
  end
66
- if raw.dig('sys', 'locale').blank?
66
+ if raw.dig('sys', 'locale').blank? && %w[Entry Asset].include?(raw.dig('sys', 'type'))
67
67
  raise ArgumentError, 'Model layer cannot represent "locale=*" entries. ' \
68
68
  "Please use a specific locale in your query. \n" \
69
69
  "(Error occurred with entry id: #{raw.dig('sys', 'id')})"
@@ -36,7 +36,6 @@ module WCC::Contentful
36
36
  # @param [Hash] options The remaining optional parameters, defined below
37
37
  # @option options [Symbol, Object] connection The Faraday connection to use to make requests.
38
38
  # Auto-discovered based on what gems are installed if this is not provided.
39
- # @option options [String] default_locale The locale query param to set by default.
40
39
  # @option options [String] environment The contentful environment to access. Defaults to 'master'.
41
40
  # @option options [Boolean] no_follow_redirects If true, do not follow 300 level redirects.
42
41
  # @option options [Number] rate_limit_wait_timeout The maximum time to block the thread waiting
@@ -51,7 +50,6 @@ module WCC::Contentful
51
50
  @options = options
52
51
  @_instrumentation = @options[:instrumentation]
53
52
  @query_defaults = {}
54
- @query_defaults[:locale] = @options[:default_locale] if @options[:default_locale]
55
53
  # default 1.5 so that we retry one time then fail if still rate limited
56
54
  # https://www.contentful.com/developers/docs/references/content-preview-api/#/introduction/api-rate-limits
57
55
  @rate_limit_wait_timeout = @options[:rate_limit_wait_timeout] || 1.5
@@ -2,6 +2,6 @@
2
2
 
3
3
  module WCC
4
4
  module Contentful
5
- VERSION = '1.4.0.rc1'
5
+ VERSION = '1.4.0.rc3'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wcc-contentful
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0.rc1
4
+ version: 1.4.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Watermark Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-28 00:00:00.000000000 Z
11
+ date: 2023-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -698,8 +698,8 @@ summary: '[![Gem Version](https://badge.fury.io/rb/wcc-contentful.svg)](https://
698
698
  credentials, or to connect without setting up all the rest of WCC::Contentful, is
699
699
  easy: ```ruby WCC::Contentful::SimpleClient::Cdn.new( # required access_token:
700
700
  ''xxxx'', space: ''1234'', # optional environment: ''staging'', # omit to use master
701
- default_locale: ''*'', rate_limit_wait_timeout: 10, instrumentation: ActiveSupport::Notifications,
702
- connection: Faraday.new { |builder| ... }, ) ``` You can also create a {WCC::Contentful::SimpleClient::Preview}
701
+ rate_limit_wait_timeout: 10, instrumentation: ActiveSupport::Notifications, connection:
702
+ Faraday.new { |builder| ... }, ) ``` You can also create a {WCC::Contentful::SimpleClient::Preview}
703
703
  to talk to the Preview API, or a {WCC::Contentful::SimpleClient::Management} to
704
704
  talk to the Management API. ### Store Layer The Store Layer represents the data
705
705
  store where Contentful entries are kept for querying. By default, `WCC::Contentful.init!`