Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Register resource extensions upfront
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite committed Apr 20, 2022
1 parent 5e990b7 commit 7e2bf0a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions lib/bridgetown-prismic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/bridgetown-prismic/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand Down
1 change: 0 additions & 1 deletion lib/bridgetown-prismic/origin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/bridgetown-prismic/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module BridgetownPrismic
VERSION = "0.2.2"
VERSION = "0.2.3"
end

0 comments on commit 7e2bf0a

Please sign in to comment.