From 7e2bf0af24f953311cf7a6dd61d7c2fa82874263 Mon Sep 17 00:00:00 2001 From: Jared White Date: Wed, 20 Apr 2022 13:17:05 -0700 Subject: [PATCH] Register resource extensions upfront --- CHANGELOG.md | 4 ++++ lib/bridgetown-prismic.rb | 4 ---- lib/bridgetown-prismic/api.rb | 6 ++++++ lib/bridgetown-prismic/origin.rb | 1 - lib/bridgetown-prismic/version.rb | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75992c7..df991f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ... +## 0.2.3 + +- Register resource extensions upfront + ## 0.2.2 - Lock Async dependency to < 2.0 until fiber race condition is resolved diff --git a/lib/bridgetown-prismic.rb b/lib/bridgetown-prismic.rb index c1c3798..775ca0e 100644 --- a/lib/bridgetown-prismic.rb +++ b/lib/bridgetown-prismic.rb @@ -14,10 +14,6 @@ def self.api = Bridgetown::Current.site.config.prismic_api require_relative "bridgetown/utils/prismic_data" Bridgetown::Model::Base.class_eval do # rubocop:disable Metrics/BlockLength - class << self - attr_accessor :extensions_have_been_registered - end - def self.import_prismic_document(doc) = new(BridgetownPrismic::Origin.import_document(doc)) def self.with_links = Bridgetown::Current.site.config.prismic_link_resolver diff --git a/lib/bridgetown-prismic/api.rb b/lib/bridgetown-prismic/api.rb index 0c1604a..8654ed1 100644 --- a/lib/bridgetown-prismic/api.rb +++ b/lib/bridgetown-prismic/api.rb @@ -20,6 +20,12 @@ def configure_prismic # rubocop:disable Metrics/AbcSize "/" end end + + Bridgetown::Model::Base.descendants.each do |klass| + next unless klass.respond_to?(:prismic_custom_type) + + Bridgetown::Resource.register_extension klass + end end def query_prismic(custom_type, options = {}) diff --git a/lib/bridgetown-prismic/origin.rb b/lib/bridgetown-prismic/origin.rb index 10baad5..619ddcc 100644 --- a/lib/bridgetown-prismic/origin.rb +++ b/lib/bridgetown-prismic/origin.rb @@ -28,7 +28,6 @@ def read raise "Could not find a specialized model class for ID `#{id}'" end - Bridgetown::Resource.register_extension klass unless klass.extensions_have_been_registered @data = klass.prismic_data(self, @prismic_document) @data[:_id_] = id @data[:_origin_] = self diff --git a/lib/bridgetown-prismic/version.rb b/lib/bridgetown-prismic/version.rb index bc485fc..0e4e616 100644 --- a/lib/bridgetown-prismic/version.rb +++ b/lib/bridgetown-prismic/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module BridgetownPrismic - VERSION = "0.2.2" + VERSION = "0.2.3" end