wcc-contentful 1.3.0 → 1.3.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 +25 -1
- data/lib/wcc/contentful/model_api.rb +2 -2
- data/lib/wcc/contentful/version.rb +1 -1
- metadata +36 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58a77a1fbe7e5a7f99d8f13142c29ccac39d7101dfbe2769f542d18e88634a40
|
4
|
+
data.tar.gz: 8a4748e01236daaf0f6bce2c32b2999e02205de77977b6fee01280ea84b83241
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 992a019411bac0fb5c14819db375ed2c8a318c94ccc78b46237598a0ece9aa3646c3b34315738e5c20b7583f43fd0fdec946594cc6e96d92fdaa1b084b425aae
|
7
|
+
data.tar.gz: 4ba8042ea71939b58d51239e4d8b325d6a714f051ff273c2cbcc4116f707eac3b0ca2b695cc73de2904bdcb9cd2f2651927c4987e4967cee514e4d5acd1e9511
|
data/README.md
CHANGED
@@ -565,7 +565,10 @@ to multiple spaces within the same ruby process! You just have to create and in
|
|
565
565
|
The {WCC::Contentful::ModelAPI} concern makes this straightforward. Start by creating your Namespace
|
566
566
|
and including the concern:
|
567
567
|
```ruby
|
568
|
-
#
|
568
|
+
# lib/my_second_space.rb
|
569
|
+
|
570
|
+
# Note: This class must be in the "lib" folder in :zeitwerk mode, otherwise Rails 6+ will unload all your constants
|
571
|
+
# that were created in the initializer. Your models which subclass this namespace may reside in the app/models directory.
|
569
572
|
class MySecondSpace
|
570
573
|
include WCC::Contentful::ModelAPI
|
571
574
|
end
|
@@ -587,6 +590,11 @@ MySecondSpace.configure do |config|
|
|
587
590
|
config.space = ENV['SECOND_CONTENTFUL_SPACE_ID']
|
588
591
|
config.environment = ENV['CONTENTFUL_ENVIRONMENT']
|
589
592
|
end
|
593
|
+
|
594
|
+
# Ensure that models are reloaded in Rails development mode
|
595
|
+
Rails.application.config.to_prepare do
|
596
|
+
MySecondSpace.reload!
|
597
|
+
end
|
590
598
|
```
|
591
599
|
|
592
600
|
Finally, use it:
|
@@ -614,6 +622,22 @@ sync_engine = MySecondSpace.services.sync_engine
|
|
614
622
|
Note that the above services are not accessible on {WCC::Contentful::Services.instance}
|
615
623
|
or via the {WCC::Contentful::ServiceAccessors}.
|
616
624
|
|
625
|
+
#### Important Note when using Zeitwerk with Rails 6+
|
626
|
+
When using Rails >= 6 with `config.autoloader = :zeitwerk`, Rails will remove any models defined in `app/models` after
|
627
|
+
initialization and then load them again when they are referenced. If you `include WCC::Contentful::ModelAPI` in a class
|
628
|
+
defined inside the `app` directory, this will have the effect of deleting all configuration that was set in the initializer
|
629
|
+
as well as the constants generated from your schema.
|
630
|
+
This will result in one of two errors:
|
631
|
+
|
632
|
+
* `NameError (uninitialized constant MySecondSpace::MyContentType)`
|
633
|
+
if you try to reference a subclass such as `MyContentType < MySecondSpace::MyContentType`
|
634
|
+
* `ArgumentError (Not yet configured!)`
|
635
|
+
if you try to `MySecondSpace.find('xxxx')` to load an Entry or Asset
|
636
|
+
|
637
|
+
The solution is to have your secondary namespace in a folder which is not in the `autoload_paths`.
|
638
|
+
We suggest using `lib`, which will work so long as you have not added the `lib` folder to the `autoload_paths` as some
|
639
|
+
uninformed StackOverflow answers suggest you do.
|
640
|
+
|
617
641
|
### Using a sync store with a second space
|
618
642
|
|
619
643
|
If you use something other than the CDNAdapter with your second space, you will
|
@@ -96,7 +96,7 @@ module WCC::Contentful::ModelAPI
|
|
96
96
|
loop do
|
97
97
|
begin
|
98
98
|
# The app may have defined a model and we haven't loaded it yet
|
99
|
-
const = parent.
|
99
|
+
const = parent.const_get(const_name)
|
100
100
|
return const if const && const < self
|
101
101
|
rescue NameError => e
|
102
102
|
raise e unless e.message =~ /uninitialized constant (.+::)*#{const_name}$/
|
@@ -156,7 +156,7 @@ module WCC::Contentful::ModelAPI
|
|
156
156
|
const_name = klass.name
|
157
157
|
begin
|
158
158
|
# the const_name is fully qualified so search from root
|
159
|
-
const = Object.
|
159
|
+
const = Object.const_get(const_name)
|
160
160
|
register_for_content_type(content_type, klass: const) if const
|
161
161
|
rescue NameError => e
|
162
162
|
msg = "Error when reloading constant #{const_name} - #{e}"
|
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.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Watermark Dev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -493,7 +493,7 @@ licenses:
|
|
493
493
|
metadata:
|
494
494
|
documentation_uri: https://watermarkchurch.github.io/wcc-contentful/1.3/wcc-contentful
|
495
495
|
rubygems_mfa_required: 'true'
|
496
|
-
post_install_message:
|
496
|
+
post_install_message:
|
497
497
|
rdoc_options: []
|
498
498
|
require_paths:
|
499
499
|
- lib
|
@@ -508,8 +508,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
508
508
|
- !ruby/object:Gem::Version
|
509
509
|
version: '0'
|
510
510
|
requirements: []
|
511
|
-
rubygems_version: 3.
|
512
|
-
signing_key:
|
511
|
+
rubygems_version: 3.3.7
|
512
|
+
signing_key:
|
513
513
|
specification_version: 4
|
514
514
|
summary: '[![Gem Version](https://badge.fury.io/rb/wcc-contentful.svg)](https://rubygems.org/gems/wcc-contentful)
|
515
515
|
[![Build Status](https://circleci.com/gh/watermarkchurch/wcc-contentful.svg?style=svg)](https://circleci.com/gh/watermarkchurch/wcc-contentful)
|
@@ -766,14 +766,19 @@ summary: '[![Gem Version](https://badge.fury.io/rb/wcc-contentful.svg)](https://
|
|
766
766
|
step. However the gem is also capable of connecting to multiple spaces within the
|
767
767
|
same ruby process! You just have to create and initialize a namespace. The {WCC::Contentful::ModelAPI}
|
768
768
|
concern makes this straightforward. Start by creating your Namespace and including
|
769
|
-
the concern: ```ruby #
|
770
|
-
|
771
|
-
|
769
|
+
the concern: ```ruby # lib/my_second_space.rb # Note: This class must be in the
|
770
|
+
"lib" folder in :zeitwerk mode, otherwise Rails 6+ will unload all your constants
|
771
|
+
# that were created in the initializer. Your models which subclass this namespace
|
772
|
+
may reside in the app/models directory. class MySecondSpace include WCC::Contentful::ModelAPI
|
773
|
+
end # app/models/other_page.rb class OtherPage < MySecondSpace::Page end ``` Then
|
774
|
+
configure it in an initializer: ```ruby # config/initializers/my_second_space.rb
|
772
775
|
MySecondSpace.configure do |config| # Make sure to point to a different schema file
|
773
776
|
from your first space! config.schema_file = Rails.root.join(''db/second-contentful-schema.json'') config.access_token
|
774
777
|
= ENV[''SECOND_CONTENTFUL_ACCESS_TOKEN''] config.preview_token = ENV[''SECOND_CONTENTFUL_PREVIEW_ACCESS_TOKEN'']
|
775
778
|
config.space = ENV[''SECOND_CONTENTFUL_SPACE_ID''] config.environment = ENV[''CONTENTFUL_ENVIRONMENT'']
|
776
|
-
end
|
779
|
+
end # Ensure that models are reloaded in Rails development mode Rails.application.config.to_prepare
|
780
|
+
do MySecondSpace.reload! end ``` Finally, use it: ```ruby OtherPage.find(''1234'')
|
781
|
+
# GET https://cdn.contentful.com/spaces/other-space/environments/other-env/entries/1234
|
777
782
|
# => #<OtherPage:0x0000000005c71a78 @created_at=2018-04-16 18:41:17 UTC...> Page.find(''1234'')
|
778
783
|
# GET https://cdn.contentful.com/spaces/first-space/environments/first-env/entries/1234
|
779
784
|
# => #<Page:0x0000000001271b70 @created_at=2018-04-15 12:02:14 UTC...> ``` The
|
@@ -783,14 +788,27 @@ summary: '[![Gem Version](https://badge.fury.io/rb/wcc-contentful.svg)](https://
|
|
783
788
|
preview_client = MySecondSpace.services.preview_client # => #<WCC::Contentful::SimpleClient::Preview:0x00007f888ccafa00
|
784
789
|
sync_engine = MySecondSpace.services.sync_engine # => #<WCC::Contentful::SyncEngine:0x00007f88960b6b40
|
785
790
|
``` Note that the above services are not accessible on {WCC::Contentful::Services.instance}
|
786
|
-
or via the {WCC::Contentful::ServiceAccessors}.
|
787
|
-
|
788
|
-
will
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
791
|
+
or via the {WCC::Contentful::ServiceAccessors}. #### Important Note when using
|
792
|
+
Zeitwerk with Rails 6+ When using Rails >= 6 with `config.autoloader = :zeitwerk`,
|
793
|
+
Rails will remove any models defined in `app/models` after initialization and then
|
794
|
+
load them again when they are referenced. If you `include WCC::Contentful::ModelAPI`
|
795
|
+
in a class defined inside the `app` directory, this will have the effect of deleting
|
796
|
+
all configuration that was set in the initializer as well as the constants generated
|
797
|
+
from your schema. This will result in one of two errors: * `NameError (uninitialized
|
798
|
+
constant MySecondSpace::MyContentType)` if you try to reference a subclass such
|
799
|
+
as `MyContentType < MySecondSpace::MyContentType` * `ArgumentError (Not yet configured!)`
|
800
|
+
if you try to `MySecondSpace.find(''xxxx'')` to load an Entry or Asset The solution
|
801
|
+
is to have your secondary namespace in a folder which is not in the `autoload_paths`.
|
802
|
+
We suggest using `lib`, which will work so long as you have not added the `lib`
|
803
|
+
folder to the `autoload_paths` as some uninformed StackOverflow answers suggest
|
804
|
+
you do. ### Using a sync store with a second space If you use something other
|
805
|
+
than the CDNAdapter with your second space, you will need to find a way to trigger
|
806
|
+
`MySecondSpace.services.sync_engine.next` to keep it up-to-date. The {WCC::Contentful::Engine}
|
807
|
+
will only manage the global SyncEngine configured by the global {WCC::Contentful.configure}. The
|
808
|
+
easiest way to do this is to set up your own Rails route to respond to Contentful
|
809
|
+
webhooks and then configure the second Contentful space to send webhooks to this
|
810
|
+
route. You could also do this by triggering it periodically in a background job
|
811
|
+
using Sidekiq and [sidekiq-scheduler](https://github.com/Moove-it/sidekiq-scheduler). ##
|
794
812
|
Development After checking out the repo, run `bin/setup` to install dependencies.
|
795
813
|
Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for
|
796
814
|
an interactive prompt that will allow you to experiment. ## Contributing Bug reports
|