wcc-contentful 1.5.1 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/app/jobs/wcc/contentful/webhook_enable_job.rb +1 -1
- data/lib/wcc/contentful/engine.rb +27 -25
- data/lib/wcc/contentful/test/double.rb +2 -2
- data/lib/wcc/contentful/test/factory.rb +2 -2
- data/lib/wcc/contentful/version.rb +1 -1
- metadata +14 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b816aba232400e71ec193b4a60220a111afc356d3d6aa3a10d77f96eacea21df
|
4
|
+
data.tar.gz: 95b27d0804915ef3effaf67e36e8e4ebcef39aa8001921d4e94a51c699c43a93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac1bcaeb7ddfe4f1f3fa2c34a542d814665e6d1428da89a4d8ae08a59686b5048d2892dc03cd9b3501a268bcf1867787a34ddeaac0b82d5791dadceef1df69e1
|
7
|
+
data.tar.gz: 7b84baba5cafff0ac07e7f0e557d08389f003918f84d2da7c10a8d7e50f60d45bd6214389b2e545803ed22964c00581920fa9f614b97d6e94a2e6e75abc090bc
|
data/README.md
CHANGED
@@ -74,10 +74,14 @@ We have successfully created caching layers using Memcached, Postgres, and an in
|
|
74
74
|
|
75
75
|
### Better Rails Integration
|
76
76
|
|
77
|
-
When we initially got started with the Contentful ruby models, we encountered one problem that was more frustrating than all others: If a field exists in the content model, but the particular entry we're working with does not have that field populated, then accessing that field raised a `NoMethodError`. This caused us to litter our code with `if defined?(entry.my_field)` which is bad practice.
|
77
|
+
When we initially got started with the Contentful ruby models, we encountered one problem that was more frustrating than all others: If a field exists in the content model, but the particular entry we're working with does not have that field populated, then accessing that field raised a `NoMethodError`. This caused us to litter our code with `if defined?(entry.my_field)` which is bad practice.
|
78
78
|
|
79
79
|
We decided it was better to not rely on `method_missing?` (what contentful.rb does), and instead to use `define_method` in an initializer to generate the methods for our models. This has the advantage that calling `.instance_methods` on a model class includes all the fields present in the content model.
|
80
80
|
|
81
|
+
Note: it appears that [contentful_rb has added an opt-in configuration to return `nil`](https://github.com/contentful/contentful_model#returning-nil-for-fields-which-arent-defined).
|
82
|
+
instead of raising `NoMethodError. We think this should be the default setting,
|
83
|
+
rather than being opt-in.
|
84
|
+
|
81
85
|
We also took advantage of Rails' naming conventions to automatically infer the content type name based on the class name. Thus in our code, we have `app/models/page.rb` which defines `class Page << WCC::Contentful::Model::Page`, and is automatically linked to the `page` content type ID. (Note: this is overridable on a per-model basis)
|
82
86
|
|
83
87
|
All our models are automatically generated at startup which improves response times at the expense of initialization time. In addition, our content model registry allows easy definition of custom models in your `app/models` directory to override fields. This plays nice with other gems like algoliasearch-rails, which allows you to declaratively manage your Algolia indexes. Another example from our flagship watermark.org:
|
@@ -13,7 +13,7 @@ module WCC::Contentful
|
|
13
13
|
client = WCC::Contentful::SimpleClient::Management.new(
|
14
14
|
**args
|
15
15
|
)
|
16
|
-
enable_webhook(client, args.slice(:receive_url, :webhook_username, :webhook_password))
|
16
|
+
enable_webhook(client, **args.slice(:receive_url, :webhook_username, :webhook_password))
|
17
17
|
end
|
18
18
|
|
19
19
|
def enable_webhook(client, receive_url:, webhook_username: nil, webhook_password: nil)
|
@@ -2,36 +2,38 @@
|
|
2
2
|
|
3
3
|
module WCC::Contentful
|
4
4
|
class Engine < ::Rails::Engine
|
5
|
-
initializer 'enable webhook' do
|
6
|
-
config
|
5
|
+
initializer 'enable webhook' do |app|
|
6
|
+
app.config.to_prepare do
|
7
|
+
config = WCC::Contentful.configuration
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
jobs = []
|
10
|
+
jobs << WCC::Contentful::SyncEngine::Job if WCC::Contentful::Services.instance.sync_engine&.should_sync?
|
11
|
+
jobs.push(*WCC::Contentful.configuration.webhook_jobs)
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
jobs.each do |job|
|
14
|
+
WCC::Contentful::WebhookController.subscribe(
|
15
|
+
->(event) do
|
16
|
+
begin
|
17
|
+
if job.respond_to?(:perform_later)
|
18
|
+
job.perform_later(event.to_h)
|
19
|
+
else
|
20
|
+
Rails.logger.error "Misconfigured webhook job: #{job} does not respond to " \
|
21
|
+
':perform_later'
|
22
|
+
end
|
23
|
+
rescue StandardError => e
|
24
|
+
warn "Error in job #{job}: #{e}"
|
25
|
+
Rails.logger.error "Error in job #{job}: #{e}"
|
21
26
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end,
|
27
|
-
with: :call
|
28
|
-
)
|
29
|
-
end
|
27
|
+
end,
|
28
|
+
with: :call
|
29
|
+
)
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
next unless config&.management_token.present?
|
33
|
+
next unless config.app_url.present?
|
33
34
|
|
34
|
-
|
35
|
+
WebhookEnableJob.set(wait: 10.seconds).perform_later if Rails.env.production?
|
36
|
+
end
|
35
37
|
end
|
36
38
|
|
37
39
|
config.generators do |g|
|
@@ -48,8 +48,8 @@ module WCC::Contentful::Test::Double
|
|
48
48
|
},
|
49
49
|
id: SecureRandom.urlsafe_base64,
|
50
50
|
type: 'Asset',
|
51
|
-
createdAt: Time.now.
|
52
|
-
updatedAt: Time.now.
|
51
|
+
createdAt: Time.now.to_formatted_s(:iso8601),
|
52
|
+
updatedAt: Time.now.to_formatted_s(:iso8601),
|
53
53
|
environment: {
|
54
54
|
sys: {
|
55
55
|
id: 'master',
|
@@ -62,8 +62,8 @@ module WCC::Contentful::Test::Factory
|
|
62
62
|
},
|
63
63
|
id: id || SecureRandom.urlsafe_base64,
|
64
64
|
type: 'Entry',
|
65
|
-
createdAt: Time.now.
|
66
|
-
updatedAt: Time.now.
|
65
|
+
createdAt: Time.now.to_formatted_s(:iso8601),
|
66
|
+
updatedAt: Time.now.to_formatted_s(:iso8601),
|
67
67
|
environment: {
|
68
68
|
sys: {
|
69
69
|
id: 'master',
|
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
|
+
version: 1.6.1
|
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-
|
11
|
+
date: 2023-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -499,7 +499,7 @@ homepage: https://github.com/watermarkchurch/wcc-contentful/wcc-contentful
|
|
499
499
|
licenses:
|
500
500
|
- MIT
|
501
501
|
metadata:
|
502
|
-
documentation_uri: https://watermarkchurch.github.io/wcc-contentful/1.
|
502
|
+
documentation_uri: https://watermarkchurch.github.io/wcc-contentful/1.6/wcc-contentful
|
503
503
|
rubygems_mfa_required: 'true'
|
504
504
|
post_install_message:
|
505
505
|
rdoc_options: []
|
@@ -516,7 +516,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
516
516
|
- !ruby/object:Gem::Version
|
517
517
|
version: '0'
|
518
518
|
requirements: []
|
519
|
-
rubygems_version: 3.
|
519
|
+
rubygems_version: 3.4.10
|
520
520
|
signing_key:
|
521
521
|
specification_version: 4
|
522
522
|
summary: '[![Gem Version](https://badge.fury.io/rb/wcc-contentful.svg)](https://rubygems.org/gems/wcc-contentful)
|
@@ -576,14 +576,16 @@ summary: '[![Gem Version](https://badge.fury.io/rb/wcc-contentful.svg)](https://
|
|
576
576
|
models, we encountered one problem that was more frustrating than all others: If
|
577
577
|
a field exists in the content model, but the particular entry we''re working with
|
578
578
|
does not have that field populated, then accessing that field raised a `NoMethodError`. This
|
579
|
-
caused us to litter our code with `if defined?(entry.my_field)` which is bad practice.
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
579
|
+
caused us to litter our code with `if defined?(entry.my_field)` which is bad practice. We
|
580
|
+
decided it was better to not rely on `method_missing?` (what contentful.rb does),
|
581
|
+
and instead to use `define_method` in an initializer to generate the methods for
|
582
|
+
our models. This has the advantage that calling `.instance_methods` on a model
|
583
|
+
class includes all the fields present in the content model. Note: it appears that
|
584
|
+
[contentful_rb has added an opt-in configuration to return `nil`](https://github.com/contentful/contentful_model#returning-nil-for-fields-which-arent-defined).
|
585
|
+
instead of raising `NoMethodError. We think this should be the default setting,
|
586
|
+
rather than being opt-in. We also took advantage of Rails'' naming conventions
|
587
|
+
to automatically infer the content type name based on the class name. Thus in our
|
588
|
+
code, we have `app/models/page.rb` which defines `class Page << WCC::Contentful::Model::Page`,
|
587
589
|
and is automatically linked to the `page` content type ID. (Note: this is overridable
|
588
590
|
on a per-model basis) All our models are automatically generated at startup which
|
589
591
|
improves response times at the expense of initialization time. In addition, our
|